当前位置:网站首页>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
边栏推荐
- 双非大厂测试员亲述:对测试员来说,学历重要吗?
- ADC采样率(HZ)是什么怎么计算
- Interview questions: how to test app performance?
- CTF exercise
- Txt file virus
- Leetcode interview question 02.07 Linked list intersection [double pointer]
- Digital transformation: five steps to promote enterprise progress
- I wish you all the best and the year of the tiger
- Yarn开启ACL用户认证之后无法查看Yarn历史任务日志解决办法
- Debezium系列之:mysql墓碑事件
猜你喜欢
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
行测-图形推理-5-一笔画类
Visual studio 2019 installation
Redis cluster installation
Microbial Health Network, How to restore Microbial Communities
Amesim2016 and matlab2017b joint simulation environment construction
数据库每日一题---第22天:最后一次登录
Ligne - raisonnement graphique - 4 - classe de lettres
C # realizes the communication between Modbus protocol and PLC
Line test - graphic reasoning -5- one stroke class
随机推荐
Line test - graphic reasoning - 3 - symmetric graphic class
一次搞明白 Session、Cookie、Token,面试问题全稿定
This time, let's clear up: synchronous, asynchronous, blocking, non blocking
LeetCode206. Reverse linked list [double pointer and recursion]
【测试面试题】页面很卡的原因分析及解决方案
Sword finger offer 27 Image of binary tree
De la famille debezium: SET ROLE statements supportant mysql8
30讲 线性代数 第五讲 特征值与特征向量
2021-01-12
行测-图形推理-8-图群类
Debezium series: support the use of variables in the Kill Command
There is another problem just online... Warm
Unity technical notes (I) inspector extension
Knowledge drop - PCB manufacturing process flow
Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to jsp-2
Nx10.0 installation tutorial
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
关于海康ipc的几个参数
Select sort (illustration +c code)
Leetcode206. Reverse linked list