LeetCode刷题(2)
1.Reverse Nodes in k-Group
将链表按K个进行分组,然后对每一个分组逆序
通过cur记住分组链表头,cur.next=head
则依次让第二个指向第一个,第三个指向第二个。。。
然后将cur.next指向新组的头,并将原来的头作为尾指向下一个分组,代码如下:
while countnode:count += 1if count < k:countnode = countnode.nextelse :countnode = countnode.nextfirst = cur.nexttmp1 = firstwhile count > 1:count -= 1tmp = cur.next.next#print tmp.valcur.next.next = tmp.next#print first.valtmp.next = firstfirst = tmpcur.next = firstcur = tmp1cur.next = countnodecount = 0
tmp在进行定位时采用cur定位,而没有采用first是因为first还要用于作为tmp的指向进行更新。
2.Divide Two Integers
在不使用乘法和除法的前提下做除法,是的减法
为了提高性能,移位
while dividend >= divisor:if dividend >= sub:dividend -= subres += csub <<= 1c <<= 1else:sub >>= 1c >>= 1
LeetCode刷题(2)相关推荐
- LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)
LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...
- LeetCode刷题记录14——257. Binary Tree Paths(easy)
LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...
- LeetCode刷题记录13——705. Design HashSet(easy)
LeetCode刷题记录13--705. Design HashSet(easy) 目录 LeetCode刷题记录13--705. Design HashSet(easy) 前言 题目 语言 思路 源 ...
- LeetCode刷题记录12——232. Implement Queue using Stacks(easy)
LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...
- LeetCode刷题记录11——290. Word Pattern(easy)
LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...
- LeetCode刷题记录10——434. Number of Segments in a String(easy)
LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...
- LeetCode刷题记录9——58. Length of Last Word(easy)
LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...
- LeetCode刷题记录8——605. Can Place Flowers(easy)
LeetCode刷题记录8--605. Can Place Flowers(easy) 目录 LeetCode刷题记录8--605. Can Place Flowers(easy) 题目 语言 思路 ...
- LeetCode刷题记录7——824. Goat Latin(easy)
LeetCode刷题记录7--824. Goat Latin(easy) 目录 LeetCode刷题记录7--824. Goat Latin(easy) 题目 语言 思路 后记 题目 题目需要将一个输 ...
- LeetCode刷题记录6——696. Count Binary Substrings(easy)
LeetCode刷题记录6--696. Count Binary Substrings(easy) 目录 LeetCode刷题记录6--696. Count Binary Substrings(eas ...
最新文章
- 牛客网练习赛44-B(快速幂+模拟)
- 深度全解卷积神经网络(附论文)
- 初学Java Web开发,请远离各种框架,从Servlet开发
- 并发基础(八) java线程的中断机制
- 一看就会的OSPF路由协议综合实验
- 【Spring 基础篇三】属性注入与属性编辑器
- Spring 核心容器类BeanDefinitionReader
- nest 架构_当有人打来您的Nest Hello时,如何让Google Home通知您
- 地图点随机分布均匀_英国标准协会(BSI)推荐的三坐标测点分布策略
- SQL Server 2005中设置Reporting Services发布web报表的匿名访问
- 11G新特性 -- variable size extents
- Trick(十二)——统计 label(序列)各个标签值出现的次数以及出现次数最多的标签
- 7 Object类型
- 使用组策略统一修改客户端本地管理员密码
- github下载的代码、怎么使用 python_Python学习20-补充内容之GitHub安装使用
- 使用XenApp/XenDesktop发布App-V应用——安装App-V服务器
- 韩国人气组合H.O.T所有专辑下载《经典》
- hive3之执行计划(Explain)、Fetch 抓取、本地模式、表的优化、Group By、笛卡尔积、行列过滤
- odoo14 Botton按钮标签属性详解及按钮图标使用
- 水倒七分、茶倒八分、酒倒满
热门文章
- 编码、解码Html代码
- Telnet服务安装及配置
- [Android]Android四大组件之Service总结
- Float浮点内存存储方式 转
- hdu_1285_确定比赛名次_201312081335
- poj 2479 (DP)
- Oracle 游标示例,带异常处理
- linux下adb连接不上解决方法
- [转] js前端解决跨域问题的8种方案(最新最全)
- eclipse打开后显示 Failed to create the part‘s controls 解决方法