当前位置: 首页 > news >正文

力扣66~70题

题66(简单):

python代码:

class Solution:def plusOne(self, digits: List[int]) -> List[int]:s_str=''.join([str(i) for i in digits])n=str(int(s_str)+1)n_str=list(n)res=[int(i) for i in n_str]return res

题67(简单):

python代码:

class Solution:def addBinary(self, a: str, b: str) -> str:a_to_i=int(a,2)b_to_i=int(b,2)res_10=a_to_i+b_to_ires_2=bin(res_10)res=str(res_2)[2:]return res

题68(困难):

分析:

感觉这题也不配困难啊,思路清晰点都随便做

python代码:

class Solution:def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:res=[]tmp_line=[]now_len=0#遍历一遍,确定每一行塞哪些单词for index,value in enumerate(words):#首先判断是否可以塞下这个单词#now_len+=单词长度+1if now_len+len(value)<=maxWidth:#如果可以塞下这个单词,那么直接塞进去now_len+=len(value)+1tmp_line.append(value)else:#如果塞不下kg_num=maxWidth-now_len+1i=0while kg_num>0:#从第一个的后面加空格tmp_line[i]+=' 'kg_num-=1i+=1if i>=len(tmp_line)-1:i=0line=' '.join(tmp_line)res.append(line)tmp_line=[value]now_len=len(value)+1#如果是最后一个单词if index==len(words)-1:line=' '.join(tmp_line)+' '*(maxWidth-now_len+1)res.append(line)return res

题69(简单):

python代码:

class Solution:def mySqrt(self, x: int) -> int:for i in range(1,x+2):if i*i>x:return i-1return 0

题70(简单):

python代码:

class Solution:def climbStairs(self, n: int) -> int:#使用动态数组auto_list=[1 for i in range(n+1)]for i in range(1,n+1):if i==1:auto_list[i]=1continueauto_list[i]=auto_list[i-1]+auto_list[i-2]return auto_list[-1]

http://www.lryc.cn/news/463458.html

相关文章:

  • Axure重要元件三——中继器添加数据
  • 矩阵系统哪家好~矩阵短视频运营~怎么矩阵OEM
  • Axure树形菜单展开与折叠
  • 开发一个微信小程序要多少钱?
  • AnaTraf | TCP重传的工作原理与优化方法
  • python从0快速上手(一)python环境搭建 windows macos linux
  • 麒麟aarch64架构下安装compat-openssl10
  • React远程组件
  • ssm教师上课系统+vue
  • 【C】分支和循环--猜数字游戏
  • Liunx 操作redis
  • C#教程笔记
  • Docker 部署 RocketMQ
  • linux安装mysql数据库(最完整的yum源安装)
  • 工业物联网关-TCP透传
  • sentinel原理源码分析系列(六)-统计指标
  • 【代理模式使用场景】
  • ARM-8 代码还原动态调试之 pstree 条件表达式
  • Spring Boot技术栈在电影评论网站中的应用
  • DDOS防护
  • 【Vue】Vue(九)OptionsAPI与CompositionAPI的区别
  • MySQL 【日期】函数大全(四)
  • Jlink 直接读取单片机数据
  • VScode运行C语言终端输出中文乱码问题解决方案
  • Leetcode刷题. 贪心算法
  • 强化学习的数学原理-01基本概念
  • D41【python 接口自动化学习】- python基础之函数
  • 思迅商云8修改最大找零金额
  • Lumerical学习——分析工具(Analysis tools)
  • 思迅商云8会员积分全部清0