当前位置:网站首页>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
边栏推荐
- 微生物健康網,如何恢複微生物群落
- Take full control! Create a "leading cockpit" for smart city construction
- Unity dynamically merges mesh textures
- Build an "immune" barrier in the cloud to prepare your data
- Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to JSP-1
- 软件测评中心▏自动化测试有哪些基本流程和注意事项?
- Basic knowledge of linked list
- 6-3 find the table length of the linked table
- PHP method of obtaining image information
- Digital transformation: five steps to promote enterprise progress
猜你喜欢

XMIND mind mapping software sharing

「开源摘星计划」Loki实现Harbor日志的高效管理

ASP.NET Core入门五

Gbu1510-asemi power supply special 15A rectifier bridge gbu1510

Sword finger offer 28 Symmetric binary tree

It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen

Line test - graphic reasoning - 1 - Chinese character class

行测-图形推理-1-汉字类

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

面试百问:如何测试App性能?
随机推荐
行测-图形推理-9-线条问题类
Debezium series: source code reading snapshot reader
What does the model number of asemi rectifier bridge kbpc1510 represent
Digital transformation: five steps to promote enterprise progress
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
肠道里的微生物和皮肤上的一样吗?
Leetcode206. Reverse linked list
DTC社群运营怎么做?
Some parameters of Haikang IPC
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
Apple further entered the financial sector through the 'virtual card' security function in IOS 16
“拧巴”的早教行业:万亿市场,难出巨头
Sword finger offer 27 Image of binary tree
Innovation today | five key elements for enterprises to promote innovation
Visual design form QT designer design gui single form program
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
行測-圖形推理-4-字母類
Ligne - raisonnement graphique - 4 - classe de lettres
关于海康ipc的几个参数
C # realizes the communication between Modbus protocol and PLC