当前位置:网站首页>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
边栏推荐
- 今日创见|企业促进创新的5大关键要素
- Unity technical notes (II) basic functions of scriptableobject
- LeetCode203. Remove linked list elements
- Visual studio 2019 installation
- Personal statement of testers from Shuangfei large factory: is education important for testers?
- Introduction to anomaly detection
- Transform XL translation
- Txt file virus
- Talk about DART's null safety feature
- Line test graph reasoning graph group class
猜你喜欢
Software test classification
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
Quick sort (diagram +c code)
Sword finger offer 28 Symmetric binary tree
Leetcode94. Middle order traversal of binary trees
Basic knowledge of binary tree
行測-圖形推理-4-字母類
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
详解全志V853上的ARM A7和RISC-V E907之间的通信方式
随机推荐
Select sort (illustration +c code)
Circumvention Technology: Registry
Ligne - raisonnement graphique - 4 - classe de lettres
Two minutes, talk about some wrong understandings of MySQL index
今日创见|企业促进创新的5大关键要素
Digital transformation: five steps to promote enterprise progress
Debezium系列之:支持 mysql8 的 set role 语句
PCL . VTK files and Mutual conversion of PCD
Micro service remote debug, nocalhost + rainbow micro service development second bullet
消费品企业敏捷创新转型案例
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
Sword finger offer 28 Symmetric binary tree
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
Leetcode206. Reverse linked list
Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
聊聊 Dart 的空安全 (null safety) 特性
Debezium系列之:支持 mysql8 的 set role 語句
6-3 find the table length of the linked table
Txt file virus
GBU1510-ASEMI电源专用15A整流桥GBU1510