当前位置:网站首页>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
边栏推荐
- Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
- 关于海康ipc的几个参数
- Personal statement of testers from Shuangfei large factory: is education important for testers?
- 今日创见|企业促进创新的5大关键要素
- Apple further entered the financial sector through the 'virtual card' security function in IOS 16
- Sword finger offer 55 - I. depth of binary tree
- iNFTnews | Web5 vs Web3:未来是一个过程,而不是目的地
- DTC社群运营怎么做?
- Are the microorganisms in the intestines the same as those on the skin?
- GBU1510-ASEMI电源专用15A整流桥GBU1510
猜你喜欢
随机推荐
Leetcode19. Delete the penultimate node of the linked list [double pointer]
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
Force deduction - question 561 - array splitting I - step by step parsing
Why is network i/o blocked?
Debezium series: MySQL tombstone event
Debezium series: binlogreader for source code reading
One question per day - pat grade B 1002 questions
Line measurement - graphic reasoning -9- line problem class
Transform XL translation
Unity与WebGL的相爱相杀
Sword finger offer 63 Maximum profit of stock
今日创见|企业促进创新的5大关键要素
行测-图形推理-4-字母类
Interview questions: how to test app performance?
6-3 find the table length of the linked table
XMIND mind mapping software sharing
Unity local coordinates and world coordinates
ADC采样率(HZ)是什么怎么计算
Unity FAQ (I) lack of references
ASP. Net core introduction V