当前位置:网站首页>Brush question 6
Brush question 6
2022-07-07 23:06:00 【Anny Linlin】
23、 climb stairs
Suppose you're climbing the stairs . need n You can reach the top of the building . Every time you climb 1 or 2 A stair . How many different ways can you climb to the top of the building ? Be careful : Given n Is a positive integer
class Solution(object): def climbStairs(self, n): if n < 2: return n dp = [1 for __ in range(n)] dp[1] = 2 for i in range(2, n): dp[i] = dp[i-1] + dp[i-2] return dp[-1]
26、 Gray code
Gray coding is a binary digital system , In this system , There is only one digit difference between two consecutive values . Given a non negative integer representing the total number of bits encoded n, Print its gray code sequence . Gray coding sequence must be in 0 start .
class Solution:
def grayCode(self, n: int) -> List[int]:
res = []
for i in range(2 ** n):
res.append((i >> 1) ^ i)
return res
33、 Circular list
Given a linked list , Return to the first node of the link where the list begins to enter . If the list has no links , Then return to null. To represent a ring in a given list , We use integers pos To indicate where the end of the list is connected to the list ( Indexes from 0 Start ). If pos yes -1, There are no links in the list . explain : It is not allowed to modify the given linked list .
def hasCycle(self, head):
if head == None or head.next == None:
return False
first = second = head
while second and second.next:
first = first.next
second = second.next.next
if first == second:
return True
return False
边栏推荐
- 行测-图形推理-9-线条问题类
- 全面掌控!打造智慧城市建设的“领导驾驶舱”
- One question per day - pat grade B 1002 questions
- Amesim2016 and matlab2017b joint simulation environment construction
- Yarn开启ACL用户认证之后无法查看Yarn历史任务日志解决办法
- LeetCode206. Reverse linked list [double pointer and recursion]
- Unity technical notes (II) basic functions of scriptableobject
- iNFTnews | Web5 vs Web3:未来是一个过程,而不是目的地
- Two minutes, talk about some wrong understandings of MySQL index
- Select sort (illustration +c code)
猜你喜欢
Sword finger offer 27 Image of binary tree
30讲 线性代数 第五讲 特征值与特征向量
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
Quick sort (diagram +c code)
聊聊 Dart 的空安全 (null safety) 特性
XMIND mind mapping software sharing
Line test - graphic reasoning - 3 - symmetric graphic class
Visual studio 2019 installation
Loki, the "open source star picking program", realizes the efficient management of harbor logs
行测-图形推理-2-黑白格类
随机推荐
2022 words for yourself
LeetCode707. Design linked list
Personal statement of testers from Shuangfei large factory: is education important for testers?
Unity technical notes (II) basic functions of scriptableobject
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
JS triangle
Debezium系列之:mysql墓碑事件
Circumvention Technology: Registry
LeetCode206. Reverse linked list [double pointer and recursion]
What is fake sharing after filling the previous hole?
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
CTF练习
Line test - graphic reasoning - 4 - alphabetic class
Knowledge drop - PCB manufacturing process flow
6-3 find the table length of the linked table
消费品企业敏捷创新转型案例
This time, let's clear up: synchronous, asynchronous, blocking, non blocking
Unity FAQ (I) lack of references
Unity与WebGL的相爱相杀
ASP.NET Core入门五