当前位置:网站首页>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
边栏推荐
- Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
- 0-5vac to 4-20mA AC current isolated transmitter / conversion module
- 「开源摘星计划」Loki实现Harbor日志的高效管理
- 小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
- Unity technical notes (I) inspector extension
- Loki, the "open source star picking program", realizes the efficient management of harbor logs
- Debezium series: introducing support for the final operator
- Nx10.0 installation tutorial
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- Quick sort (diagram +c code)
猜你喜欢
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
Basic knowledge of binary tree
Select sort (illustration +c code)
ASP. Net core introduction V
Line test graph reasoning graph group class
Line test - graphic reasoning -5- one stroke class
行测-图形推理-2-黑白格类
DTC社群运营怎么做?
CTF exercise
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
随机推荐
Microbial Health Network, How to restore Microbial Communities
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
Unity technical notes (I) inspector extension
Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
每日一题——PAT乙级1002题
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
[network] Introduction to C language
软件测评中心▏自动化测试有哪些基本流程和注意事项?
Signal feature extraction +lstm to realize gear reducer fault diagnosis -matlab code
Sword finger offer 63 Maximum profit of stock
Debezium系列之:支持 mysql8 的 set role 語句
面试百问:如何测试App性能?
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
行测-图形推理-4-字母类
2022 words for yourself
安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
Debezium series: introducing support for the final operator
30讲 线性代数 第五讲 特征值与特征向量
Debezium系列之:支持 mysql8 的 set role 语句
Basic knowledge of binary tree