当前位置:网站首页>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
边栏推荐
- Txt file virus
- There is another problem just online... Warm
- One question per day - pat grade B 1002 questions
- The author of LinkedList said he didn't use LinkedList himself
- XMIND mind mapping software sharing
- Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
- Yarn开启ACL用户认证之后无法查看Yarn历史任务日志解决办法
- 开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- DTC社群运营怎么做?
猜你喜欢

Line test - graphic reasoning -7- different graphic classes

今日创见|企业促进创新的5大关键要素

What is fake sharing after filling the previous hole?

Talk about DART's null safety feature

微生物健康網,如何恢複微生物群落

Unity and webgl love each other

Leetcode1984. Minimum difference in student scores

Transparent i/o model from beginning to end

肠道里的微生物和皮肤上的一样吗?

Personal statement of testers from Shuangfei large factory: is education important for testers?
随机推荐
7-18 simple simulation of banking business queue
LeetCode707. Design linked list
What is fake sharing after filling the previous hole?
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
GBU1510-ASEMI电源专用15A整流桥GBU1510
聊聊 Dart 的空安全 (null safety) 特性
Quick sort (diagram +c code)
Line measurement - graphic reasoning -9- line problem class
Redis集群安装
Software test classification
【测试面试题】页面很卡的原因分析及解决方案
Micro service remote debug, nocalhost + rainbow micro service development second bullet
Debezium系列之:引入对 LATERAL 运算符的支持
Leetcode1984. Minimum difference in student scores
Line test - graphic reasoning - 3 - symmetric graphic class
What is ADC sampling rate (Hz) and how to calculate it
Ligne - raisonnement graphique - 4 - classe de lettres
7-51 combination of two ordered linked list sequences
微生物健康网,如何恢复微生物群落
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution