当前位置:网站首页>Brush question 3
Brush question 3
2022-07-07 23:05:00 【Anny Linlin】
7、 subject : Write a function to find the longest common prefix in the string array . If no common prefix exists , Returns an empty string .
Example :
explain : All inputs contain only lowercase letters a-z.
class Solution(object):
def longestCommonPrefix(self, strs):
if not strs:
return “”
for i in range(len(strs[0])):
for string in strs[1:]:
if i >= len(string) or string[i] != strs[0][i]:
return strs[0][:i]
return strs[0]
8、 The sum of three numbers
class Solution(object):
def threeSum(self, nums):
res = []
nums.sort()
n=len(nums)
for i in range(n-2):
if i0 or nums[i]>nums[i-1]:
left,right = i+1,n-1
while left<right:
ident = nums[i]+nums[left]+nums[right]
if ident0:
res.append([nums[i],nums[left],nums[right]])
left+=1
right-=1
while left<right and nums[left]==nums[left-1]:
left+=1
while left<right and nums[right]==nums[right+1]:
right-=1
elif ident<0:
left+=1
else:
right-=1
return res
9、 Container for the most water
class Solution:
def maxArea(self, height):
l = 0
r = len(height) - 1
s = 0
while l < r:
s = max( (r-l)*min(height[l], height[r]), s)
if height[l] > height[r]:
r -= 1
else:
l += 1
return s
边栏推荐
- 微生物健康网,如何恢复微生物群落
- Visual studio 2019 installation
- Basic knowledge of binary tree
- LeetCode707. Design linked list
- Ni9185 and ni9234 hardware settings in Ni Max
- Debezium series: MySQL tombstone event
- Unity and webgl love each other
- Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
- De la famille debezium: SET ROLE statements supportant mysql8
- What is ADC sampling rate (Hz) and how to calculate it
猜你喜欢
![[record of question brushing] 3 Longest substring without duplicate characters](/img/44/1cd8128d93c9c273e0f4718d84936e.png)
[record of question brushing] 3 Longest substring without duplicate characters

Basic knowledge of binary tree

数字化转型:五个步骤推动企业进步
![LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]](/img/5e/e442c8649b9123a9d9df7c0d61a564.jpg)
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]

Sword finger offer 28 Symmetric binary tree

Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~

The author of LinkedList said he didn't use LinkedList himself

What does the model number of asemi rectifier bridge kbpc1510 represent

行测-图形推理-7-相异图形类

Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
随机推荐
【测试面试题】页面很卡的原因分析及解决方案
Debezium系列之:mysql墓碑事件
The author of LinkedList said he didn't use LinkedList himself
PCL .vtk文件与.pcd的相互转换
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
0-5vac to 4-20mA AC current isolated transmitter / conversion module
Quick sort (diagram +c code)
PHP method of obtaining image information
Leetcode206. Reverse linked list
30讲 线性代数 第五讲 特征值与特征向量
The PHP source code of the new website + remove authorization / support burning goose instead of pumping
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
数据库每日一题---第22天:最后一次登录
Microbial Health Network, How to restore Microbial Communities
PHP records the pitfalls encountered in the complete docking of Tencent cloud live broadcast and im live group chat
Database daily question --- day 22: last login
Debezium系列之:源码阅读之BinlogReader
C # realizes the communication between Modbus protocol and PLC
ASEMI整流桥KBPC1510的型号数字代表什么
Sword finger offer 28 Symmetric binary tree