当前位置:网站首页>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
边栏推荐
- (ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性
- dotnet core 输出调试信息到 DebugView 软件
- 力扣学习---0804
- 火灾报警联网FC18中CAN光端机常见问题解答和使用指导
- 【AI+医疗】斯坦福大学最新博士论文《深度学习在医学影像理解中的应用》,205页pdf
- vantui 组件 van-field 路由切换时,字体样式混乱问题
- 开发那些事儿:如何通过EasyCVR平台获取监控现场的人流量统计数据?
- A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?
- Flink/Scala - Storing data with RedisSink
- Flask framework implementations registered encryption, a Flask enterprise class learning 】 【
猜你喜欢

运力升级助力算力流转,中国数字经济的加速时刻

【RTOS训练营】关于上课和答疑

网站设计师:Nicepage 4.15 Crack By Xacker

12. SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值

npm配置国内镜像(淘宝镜像)

A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?

DOM Clobbering的原理及应用

Flask框架实现注册加密功能详解【Flask企业课学习】

入选爱分析·银行数字化厂商全景报告,网易数帆助力金融数字化场景落地

巴比特 | 元宇宙每日必读:微博动漫将招募全球各类虚拟偶像并为其提供扶持...
随机推荐
浅谈web网站架构演变过程
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
PHP代码审计7—文件上传漏洞
EuROC dataset format and related codes
Global electronics demand slows: Samsung's Vietnam plant significantly reduces capacity
开篇-开启全新的.NET现代应用开发体验
使用.NET简单实现一个Redis的高性能克隆版(二)
Enterprise survey correlation analysis case
Flask framework implementations registered encryption, a Flask enterprise class learning 】 【
MySQL安装教程(详细)
2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案
链表的经典入门LeetCode题目
mysql cdc 为什么需要RELOAD 这个权限?这个权限在采集数据的过程中的作用是什么?有哪
【注册荣耀开发者】赢【荣耀70】手机
【STM32】STM32单片机总目录
How does EasyCVR call the double-speed playback of device recording through the interface?
Understanding of margin collapse and coincidence
ros2订阅esp32发布的电池电压数据
limux入门3—磁盘与分区管理
基于 eBPF 的 Kubernetes 可观测实践