当前位置:网站首页>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
边栏推荐
- Debezium series: introducing support for the final operator
- CTF练习
- Force deduction - question 561 - array splitting I - step by step parsing
- Take full control! Create a "leading cockpit" for smart city construction
- Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
- 消费品企业敏捷创新转型案例
- Sword finger offer 55 - I. depth of binary tree
- 安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
- Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
- 今日创见|企业促进创新的5大关键要素
猜你喜欢
Leetcode19. Delete the penultimate node of the linked list [double pointer]
行测-图形推理-5-一笔画类
Cause analysis and solution of too laggy page of [test interview questions]
ASEMI整流桥KBPC1510的型号数字代表什么
数字化转型:五个步骤推动企业进步
Software test classification
XMIND mind mapping software sharing
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
微生物健康網,如何恢複微生物群落
DTC社群运营怎么做?
随机推荐
Innovation today | five key elements for enterprises to promote innovation
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
What is ADC sampling rate (Hz) and how to calculate it
Leetcode206. Reverse linked list
Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
Debezium series: set role statement supporting mysql8
Sword finger offer 55 - I. depth of binary tree
PHP method of obtaining image information
Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?
行测-图形推理-9-线条问题类
Unity dynamically merges mesh textures
Leetcode1984. Minimum difference in student scores
Line test - graphic reasoning - 3 - symmetric graphic class
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
Personal statement of testers from Shuangfei large factory: is education important for testers?
肠道里的微生物和皮肤上的一样吗?
每日一题——PAT乙级1002题
微生物健康网,如何恢复微生物群落
Debezium系列之:支持 mysql8 的 set role 语句