当前位置:网站首页>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
边栏推荐
- 数据库每日一题---第22天:最后一次登录
- Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
- Nx10.0 installation tutorial
- Line test graph reasoning graph group class
- 今日创见|企业促进创新的5大关键要素
- Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
- Visual studio 2019 installation
- Debezium系列之:支持 mysql8 的 set role 語句
- Unity dynamically merges mesh textures
- What does the model number of asemi rectifier bridge kbpc1510 represent
猜你喜欢

Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment

Line test - graphic reasoning - 1 - Chinese character class

CTF练习

Gbu1510-asemi power supply special 15A rectifier bridge gbu1510

LeetCode203. Remove linked list elements

行测-图形推理-9-线条问题类

【刷题记录】3. 无重复字符的最长子串

行測-圖形推理-4-字母類

Sword finger offer 55 - I. depth of binary tree

Unity and webgl love each other
随机推荐
行测-图形推理-8-图群类
安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
聊聊 Dart 的空安全 (null safety) 特性
Nx10.0 installation tutorial
Force deduction - question 561 - array splitting I - step by step parsing
软件测评中心▏自动化测试有哪些基本流程和注意事项?
Debezium系列之:源码阅读之SnapshotReader
Line test graph reasoning graph group class
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
Unity technical notes (II) basic functions of scriptableobject
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
三菱PLC slmp(mc)协议
2021-01-12
De la famille debezium: SET ROLE statements supportant mysql8
ADC采样率(HZ)是什么怎么计算
行测-图形推理-5-一笔画类
Circumvention Technology: Registry
Database daily question --- day 22: last login
Innovation today | five key elements for enterprises to promote innovation
PCL .vtk文件与.pcd的相互转换