当前位置:网站首页>lc marathon 8.3
lc marathon 8.3
2022-08-04 18:36:00 【云霞川】
文章目录
899. 有序队列
当 K == 1 时, 只能循环移动每个元素,无法改变相对位置。因此只需要获取循环移动过程中字典序最小的序列。 当 K > 1 时, 可以生成当前字符串的任意序列。因此将原字符串排序生成字典序最小的序列。
dic=set()
minx=None
class Solution:
def orderlyQueue(self, s: str, k: int) -> str:
if k==1:
minx=s
for index,st in enumerate(s):
if s[1:]+s[0] <minx:
minx=s[1:]+s[0]
s=s[1:]+s[0]
return minx
else:
return "".join(sorted(s))
322. 零钱兑换
简单的背包问题,用动态规划即可
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
# dp[n] 表示n的时候最少的硬币数目
# dp[n] = min(dp[n-l]) for l in ...
dp=[0 for i in range(amount+1)]
dp[0]=0
for i in range(1,amount+1):
ls=[]
for coin in coins:
if i-coin>=0 and dp[i-coin]!=-1:
ls.append(dp[i-coin]+1)
if len(ls)!=0:
dp[i]=min(ls)
else:
dp[i]=-1
return dp[amount]
2279. 装满石头的背包的最大数量
贪心 排序即可
class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
needs=[cap-rock for cap,rock in zip(capacity,rocks)]
needs=sorted(needs)
ns=0
for need in needs:
if additionalRocks>=need:
additionalRocks-=need
ns+=1
else:
break
return ns
334. 递增的三元子序列
算出 从前往后的最小值数组
从后往前的最大值数组
有一个数 比它左边的最小值都大
又比右边的最大值都小
那就满足啦
class Solution:
def increasingTriplet(self, nums: List[int]) -> bool:
mins=[]
min_num=nums[0]
for num in nums:
if num <= min_num:
min_num=num
mins.append(min_num)
maxs=[]
max_num=nums[-1]
for num in nums[::-1]:
if num>=max_num:
max_num=num
maxs.append(max_num)
maxs=maxs[::-1]
for index,num in enumerate(nums):
if index!=0 and index!=len(nums)-1:
if num>mins[index-1] and num<maxs[index+1]:
return True
return False
边栏推荐
- Google Earth Engine APP——一键在线查看全球1984-至今年的影像同时加载一个影像分析
- 使用.NET简单实现一个Redis的高性能克隆版(二)
- EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
- Flask framework implementations registered encryption, a Flask enterprise class learning 】 【
- ECCV 2022 | FPN错位对齐,实现高效半监督目标检测(PseCo)
- 方法的重写
- 单行、多行文本超出显示省略号
- 2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers
- curl命令的那些事
- 动态数组底层是如何实现的
猜你喜欢
(ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性
老电脑怎么重装系统win10
开篇-开启全新的.NET现代应用开发体验
After EasyCVR is locally connected to the national standard device to map the public network, the local device cannot play and cascade the solution
浅谈web网站架构演变过程
2018年南海区小学生程序设计竞赛详细答案
当项目中自动格式化插件Prettier和ESLint冲突报错时如何解决
工业元宇宙对工业带来的改变
MySQL安装教程(详细)
关于使用腾讯云HiFlow场景连接器每天提醒签到打卡
随机推荐
路由技术
【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
实验室专利书写指南
猜数字游戏
MMDetection 使用示例:从入门到出门
【填空题】130道面试填空题
LVS负载均衡群集之原理叙述
Hezhou Cat1 4G module Air724UG is configured with RNDIS network card or PPP dial-up, and the development board is connected to the Internet through the RNDIS network card (taking the RV1126/1109 devel
袋鼠云思枢:数驹DTengine,助力企业构建高效的流批一体数据湖计算平台
GBase8s存储过程
EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
力扣学习---0804
合宙Cat1 4G模块Air724UG配置RNDIS网卡或PPP拨号,通过RNDIS网卡使开发板上网(以RV1126/1109开发板为例)
Regardless of whether you are a public, professional or non-major class, I have been sorting out the learning route for a long time here, and the learning route I have summarized is not yet rolled up
DOM Clobbering的原理及应用
Day018 继承
Homework 8.3 Thread Synchronization Mutex Condition Variables
2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers
DHCP&OSPF combined experimental demonstration (Huawei routing and switching equipment configuration)
Documentary on Security Reinforcement of Network Range Monitoring System (1)—SSL/TLS Encrypted Transmission of Log Data