当前位置:网站首页>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
边栏推荐
- 微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
- Leetcode1984. Minimum difference in student scores
- Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
- Debezium系列之: 支持在 KILL 命令中使用变量
- Common verification rules of form components -2 (continuously updating ~)
- iNFTnews | NFT技术的广泛应用及其存在的问题
- Redis cluster installation
- Two minutes, talk about some wrong understandings of MySQL index
- Microbial health network, how to restore microbial communities
- Unity technical notes (II) basic functions of scriptableobject
猜你喜欢

0-5VAC转4-20mA交流电流隔离变送器/转换模块

Ni9185 and ni9234 hardware settings in Ni Max

Interview questions: how to test app performance?

Anta DTC | Anta transformation, building a growth flywheel that is not only FILA

面试百问:如何测试App性能?

Early childhood education industry of "screwing bar": trillion market, difficult to be a giant

数字化转型:五个步骤推动企业进步

Line test - graphic reasoning -5- one stroke class

消费品企业敏捷创新转型案例

Transform XL translation
随机推荐
Two minutes, talk about some wrong understandings of MySQL index
数字化转型:五个步骤推动企业进步
Years of summary, some core suggestions for learning programming
行测-图形推理-2-黑白格类
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Unity technical notes (I) inspector extension
CTF exercise
Debezium series: source code reading snapshot reader
Unity FAQ (I) lack of references
Debezium系列之:源码阅读之SnapshotReader
Sword finger offer 63 Maximum profit of stock
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
Knowledge drop - PCB manufacturing process flow
QT graphicsview graphical view usage summary with flow chart development case prototype
7-51 combination of two ordered linked list sequences
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
Common verification rules of form components -2 (continuously updating ~)
6-3 find the table length of the linked table
ADC采样率(HZ)是什么怎么计算
PCL . VTK files and Mutual conversion of PCD