当前位置:网站首页>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
边栏推荐
- 行测-图形推理-6-相似图形类
- Line measurement - graphic reasoning -9- line problem class
- There is another problem just online... Warm
- Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
- 行测-图形推理-3-对称图形类
- CTF练习
- PHP records the pitfalls encountered in the complete docking of Tencent cloud live broadcast and im live group chat
- Unity local coordinates and world coordinates
- Basic knowledge of binary tree
- Cause analysis and solution of too laggy page of [test interview questions]
猜你喜欢
行测-图形推理-9-线条问题类
PCL . VTK files and Mutual conversion of PCD
知识点滴 - PCB制造工艺流程
PHP method of obtaining image information
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
双非大厂测试员亲述:对测试员来说,学历重要吗?
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
【测试面试题】页面很卡的原因分析及解决方案
Line test - graphic reasoning - 6 - similar graphic classes
聊聊 Dart 的空安全 (null safety) 特性
随机推荐
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
PCL .vtk文件与.pcd的相互转换
行测-图形推理-9-线条问题类
消费品企业敏捷创新转型案例
7-18 simple simulation of banking business queue
Sword finger offer 28 Symmetric binary tree
Two minutes, talk about some wrong understandings of MySQL index
Basic knowledge of linked list
There is another problem just online... Warm
Line test - graphic reasoning - 6 - similar graphic classes
Unity local coordinates and world coordinates
全面掌控!打造智慧城市建设的“领导驾驶舱”
Unity dynamically merges mesh textures
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
[network] Introduction to C language
DTC社群运营怎么做?
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Build an "immune" barrier in the cloud to prepare your data
行测-图形推理-1-汉字类
Basic knowledge of binary tree