当前位置:网站首页>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
边栏推荐
- How to operate DTC community?
- Line test - graphic reasoning -5- one stroke class
- 数字藏品加速出圈,MarsNFT助力多元化文旅经济!
- LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
- 0-5vac to 4-20mA AC current isolated transmitter / conversion module
- Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to jsp-2
- [language programming] exe virus code example
- There is another problem just online... Warm
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- 【测试面试题】页面很卡的原因分析及解决方案
猜你喜欢

Unity FAQ (I) lack of references

DTC社群运营怎么做?

Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb

Ni9185 and ni9234 hardware settings in Ni Max

What does the model number of asemi rectifier bridge kbpc1510 represent

Why is network i/o blocked?

行测-图形推理-5-一笔画类

Transform XL translation

「开源摘星计划」Loki实现Harbor日志的高效管理

面试百问:如何测试App性能?
随机推荐
Debezium系列之:源码阅读之BinlogReader
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
行测-图形推理-4-字母类
Yarn开启ACL用户认证之后无法查看Yarn历史任务日志解决办法
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
Leetcode interview question 02.07 Linked list intersection [double pointer]
Line test - graphic reasoning -5- one stroke class
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Unity local coordinates and world coordinates
Unity and webgl love each other
There is another problem just online... Warm
Transform XL translation
C # realizes the communication between Modbus protocol and PLC
今日创见|企业促进创新的5大关键要素
One question per day - pat grade B 1002 questions
Software test classification
Knowledge drop - PCB manufacturing process flow
软件测评中心▏自动化测试有哪些基本流程和注意事项?
Line test - graphic reasoning -7- different graphic classes