当前位置:网站首页>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
边栏推荐
- 【刷题记录】3. 无重复字符的最长子串
- ASEMI整流桥KBPC1510的型号数字代表什么
- Debezium系列之:支持 mysql8 的 set role 语句
- Transparent i/o model from beginning to end
- XMIND mind mapping software sharing
- Line test - graphic reasoning - 1 - Chinese character class
- Leetcode94. Middle order traversal of binary trees
- Microbial Health Network, How to restore Microbial Communities
- Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
- What is fake sharing after filling the previous hole?
猜你喜欢

Leetcode94. Middle order traversal of binary trees
![[record of question brushing] 3 Longest substring without duplicate characters](/img/44/1cd8128d93c9c273e0f4718d84936e.png)
[record of question brushing] 3 Longest substring without duplicate characters

Ligne - raisonnement graphique - 4 - classe de lettres

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

行测-图形推理-1-汉字类

Understand the session, cookie and token at one time, and the interview questions are all finalized

微生物健康網,如何恢複微生物群落

Force deduction - question 561 - array splitting I - step by step parsing

Personal statement of testers from Shuangfei large factory: is education important for testers?

CTF exercise
随机推荐
Transparent i/o model from beginning to end
Sword finger offer 63 Maximum profit of stock
Visual studio 2019 installation
2021-01-12
肠道里的微生物和皮肤上的一样吗?
ASEMI整流桥KBPC1510的型号数字代表什么
Micro service remote debug, nocalhost + rainbow micro service development second bullet
面试百问:如何测试App性能?
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
[network] Introduction to C language
行测-图形推理-2-黑白格类
数字化转型:五个步骤推动企业进步
行测-图形推理-3-对称图形类
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
Debezium系列之:源码阅读之BinlogReader
微生物健康網,如何恢複微生物群落
LeetCode144. Preorder traversal of binary tree
Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
Microbial Health Network, How to restore Microbial Communities
There is another problem just online... Warm