当前位置:网站首页>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
边栏推荐
- 「开源摘星计划」Loki实现Harbor日志的高效管理
- Software evaluation center ▏ what are the basic processes and precautions for automated testing?
- Class implementation of linear stack and linear queue (another binary tree pointer version)
- Sword finger offer 55 - I. depth of binary tree
- Two minutes, talk about some wrong understandings of MySQL index
- Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
- Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
- Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
- Sword finger offer 63 Maximum profit of stock
- LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
猜你喜欢

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

Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~

Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?

iNFTnews | NFT技术的广泛应用及其存在的问题

Leetcode1984. Minimum difference in student scores

“拧巴”的早教行业:万亿市场,难出巨头

详解全志V853上的ARM A7和RISC-V E907之间的通信方式

I wish you all the best and the year of the tiger

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

数字化转型:五个步骤推动企业进步
随机推荐
Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?
肠道里的微生物和皮肤上的一样吗?
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
Leetcode94. Middle order traversal of binary trees
LeetCode707. Design linked list
Basic knowledge of linked list
Txt file virus
Innovation today | five key elements for enterprises to promote innovation
嵌入式音频开发中的两种曲线
Digital transformation: five steps to promote enterprise progress
Why is network i/o blocked?
一次搞明白 Session、Cookie、Token,面试问题全稿定
[language programming] exe virus code example
Two minutes, talk about some wrong understandings of MySQL index
Talk about DART's null safety feature
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Line test - graphic reasoning - 2 - black and white lattice class
「开源摘星计划」Loki实现Harbor日志的高效管理
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
Debezium series: binlogreader for source code reading