当前位置:网站首页>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
边栏推荐
- Visual studio 2019 installation
- Line test - graphic reasoning -7- different graphic classes
- 软件测评中心▏自动化测试有哪些基本流程和注意事项?
- Debezium series: support the use of variables in the Kill Command
- Some parameters of Haikang IPC
- 数据库每日一题---第22天:最后一次登录
- Unity local coordinates and world coordinates
- Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
- XMIND mind mapping software sharing
- LeetCode206. Reverse linked list [double pointer and recursion]
猜你喜欢

Line test - graphic reasoning - 6 - similar graphic classes

数字藏品加速出圈,MarsNFT助力多元化文旅经济!

What is fake sharing after filling the previous hole?

I wish you all the best and the year of the tiger

Line test - graphic reasoning - 3 - symmetric graphic class

Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?

LeetCode707. Design linked list

Software test classification

Leetcode1984. Minimum difference in student scores

Basic knowledge of binary tree
随机推荐
数字藏品加速出圈,MarsNFT助力多元化文旅经济!
Why is network i/o blocked?
ASP. Net core introduction V
Debezium系列之:源码阅读之SnapshotReader
Debezium系列之:引入对 LATERAL 运算符的支持
行测-图形推理-1-汉字类
Unity and webgl love each other
ADC采样率(HZ)是什么怎么计算
Force deduction - question 561 - array splitting I - step by step parsing
CTF练习
行测-图形推理-2-黑白格类
Leetcode206. Reverse linked list
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Debezium系列之:支持 mysql8 的 set role 語句
Qt Graphicsview图形视图使用总结附流程图开发案例雏形
Debezium series: MySQL tombstone event
Debezium系列之: 支持在 KILL 命令中使用变量
GBU1510-ASEMI电源专用15A整流桥GBU1510
Redis official ORM framework is more elegant than redistemplate
筑起云端 “免疫”屏障,让你的数据有备无患