当前位置:网站首页>Brush question 5
Brush question 5
2022-07-07 23:06:00 【Anny Linlin】
16、 String multiplication
class Solution: def multiply(self, num1, num2): num1 = num1[::-1] num2 = num2[::-1] length1 = len(num1) length2 = len(num2) temp = [0 for __ in range(length1 + length2)] for i in range(len(num1)): for j in range(len(num2)): temp[i+j] += int(num1[i]) * int(num2[j]) print temp list_ = [] for i in range(len(temp)): digit = temp[i] % 10 carry = temp[i] / 10 if i < len(temp)-1: temp[i+1] += carry list_.insert(0, str(digit)) while list_[0] == '0' and len(list_) > 1: list_.pop(0) return ''.join(list_)
20、 Spiral matrix
class Solution:
def spiralOrder(self, matrix):
res=[]
m=len(matrix)
if m==0:
return res
else:
n=len(matrix[0])
if n==0:
return res
count=(m+1)//2
k=0
su=m*n
cc=0
while k<count and cc<su:
for i in range(k,n-k):
res.append(matrix[k][i])
cc+=1
for i in range(k+1,m-1-k):
res.append(matrix[i][n-1-k])
cc+=1
if k!=m-1-k:
for i in range(k,n-k):
res.append(matrix[m-1-k][n-1-i])
cc+=1
if k!=n-1-k:
for i in range(k+1,m-1-k):
res.append(matrix[m-1-i][k])
cc+=1
k+=1
return res
21、 Rotate the list
class Solution:
def rotateRight(self, head: ListNode, k: int) -> ListNode:
if not head:
return None
length = 0
index = head
while index.next:
index = index.next
length += 1
index.next = head
length = length + 1
k = k % length
for i in range(length - k):
head = head.next
index = index.next
index.next = None
return head
边栏推荐
- The PHP source code of the new website + remove authorization / support burning goose instead of pumping
- DTC社群运营怎么做?
- The wonderful relationship between message queue and express cabinet
- Ni9185 and ni9234 hardware settings in Ni Max
- The author of LinkedList said he didn't use LinkedList himself
- Sword finger offer 55 - I. depth of binary tree
- Talk about DART's null safety feature
- Qt Graphicsview图形视图使用总结附流程图开发案例雏形
- Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
- Unity dynamically merges mesh textures
猜你喜欢
CTF练习
一次搞明白 Session、Cookie、Token,面试问题全稿定
行测-图形推理-3-对称图形类
Knowledge drop - PCB manufacturing process flow
Line test - graphic reasoning - 1 - Chinese character class
安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
ASEMI整流桥KBPC1510的型号数字代表什么
Database daily question --- day 22: last login
随机推荐
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
Interview questions: how to test app performance?
LeetCode707. Design linked list
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
Digital transformation: five steps to promote enterprise progress
Talk about DART's null safety feature
CTF练习
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
Build an "immune" barrier in the cloud to prepare your data
Some parameters of Haikang IPC
Unity technical notes (I) inspector extension
微生物健康網,如何恢複微生物群落
PCL .vtk文件与.pcd的相互转换
Select sort (illustration +c code)
Class implementation of linear stack and linear queue (another binary tree pointer version)
Leetcode1984. Minimum difference in student scores
行测-图形推理-5-一笔画类
Debezium series: set role statement supporting mysql8
Loki, the "open source star picking program", realizes the efficient management of harbor logs
Microbial Health Network, How to restore Microbial Communities