当前位置:网站首页>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
边栏推荐
- Redis official ORM framework is more elegant than redistemplate
- Txt file virus
- ASP. Net core introduction V
- The wonderful relationship between message queue and express cabinet
- Understand the autograd package in pytorch
- 软件测评中心▏自动化测试有哪些基本流程和注意事项?
- 行测-图形推理-4-字母类
- 消费品企业敏捷创新转型案例
- Unity 动态合并网格纹理
- Qt Graphicsview图形视图使用总结附流程图开发案例雏形
猜你喜欢
行测-图形推理-5-一笔画类
Sword finger offer 27 Image of binary tree
Leetcode19. Delete the penultimate node of the linked list [double pointer]
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
详解全志V853上的ARM A7和RISC-V E907之间的通信方式
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
双非大厂测试员亲述:对测试员来说,学历重要吗?
数字藏品加速出圈,MarsNFT助力多元化文旅经济!
Microbial Health Network, How to restore Microbial Communities
随机推荐
「开源摘星计划」Loki实现Harbor日志的高效管理
知识点滴 - PCB制造工艺流程
7-51 combination of two ordered linked list sequences
PHP method of obtaining image information
Time convolution Network + soft threshold + attention mechanism to realize residual life prediction of mechanical equipment
PCL . VTK files and Mutual conversion of PCD
详解全志V853上的ARM A7和RISC-V E907之间的通信方式
CTF练习
Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
Transparent i/o model from beginning to end
[record of question brushing] 3 Longest substring without duplicate characters
今日创见|企业促进创新的5大关键要素
Unity technical notes (I) inspector extension
聊聊 Dart 的空安全 (null safety) 特性
行测-图形推理-5-一笔画类
Signal feature extraction +lstm to realize gear reducer fault diagnosis -matlab code
[network] Introduction to C language
Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
Cases of agile innovation and transformation of consumer goods enterprises
The author of LinkedList said he didn't use LinkedList himself