当前位置:网站首页>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
边栏推荐
- 聊聊 Dart 的空安全 (null safety) 特性
- CTF exercise
- Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
- The author of LinkedList said he didn't use LinkedList himself
- Leetcode19. Delete the penultimate node of the linked list [double pointer]
- XMIND mind mapping software sharing
- Unity与WebGL的相爱相杀
- Transparent i/o model from beginning to end
- Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?
- Sword finger offer 28 Symmetric binary tree
猜你喜欢
Unity与WebGL的相爱相杀
Are the microorganisms in the intestines the same as those on the skin?
[record of question brushing] 3 Longest substring without duplicate characters
Understand the session, cookie and token at one time, and the interview questions are all finalized
Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to jsp-2
消费品企业敏捷创新转型案例
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Amesim2016 and matlab2017b joint simulation environment construction
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Line test graph reasoning graph group class
随机推荐
The PHP source code of the new website + remove authorization / support burning goose instead of pumping
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
[network] Introduction to C language
Take full control! Create a "leading cockpit" for smart city construction
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
行测-图形推理-5-一笔画类
Sword finger offer 27 Image of binary tree
Leetcode206. Reverse linked list
[untitled] reprint melting ice - track icedid server with a few simple steps
Debezium series: introducing support for the final operator
软件测评中心▏自动化测试有哪些基本流程和注意事项?
Select sort (illustration +c code)
GBU1510-ASEMI电源专用15A整流桥GBU1510
消息队列与快递柜之间妙不可言的关系
Visual studio 2019 installation
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
Line test - graphic reasoning - 6 - similar graphic classes
ASEMI整流桥KBPC1510的型号数字代表什么
Debezium系列之: 支持在 KILL 命令中使用变量
Interview questions: how to test app performance?