当前位置:网站首页>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
边栏推荐
- ASP.NET Core入门五
- LeetCode206. Reverse linked list [double pointer and recursion]
- Basic knowledge of binary tree
- Unity technical notes (II) basic functions of scriptableobject
- PCL . VTK files and Mutual conversion of PCD
- Debezium series: MySQL tombstone event
- LeetCode144. Preorder traversal of binary tree
- Unity and webgl love each other
- Line test - graphic reasoning -5- one stroke class
- Txt file virus
猜你喜欢

C # realizes the communication between Modbus protocol and PLC

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

PHP method of obtaining image information

行测-图形推理-8-图群类

LeetCode144. Preorder traversal of binary tree

Use JfreeChart to generate curves, histograms, pie charts, and distribution charts and display them to jsp-2

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

The author of LinkedList said he didn't use LinkedList himself

今日创见|企业促进创新的5大关键要素

Gbu1510-asemi power supply special 15A rectifier bridge gbu1510
随机推荐
详解全志V853上的ARM A7和RISC-V E907之间的通信方式
C # realizes the communication between Modbus protocol and PLC
肠道里的微生物和皮肤上的一样吗?
LeetCode203. Remove linked list elements
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Microservice Remote debug, nocalhost + rainbond microservice Development second Bomb
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
ASEMI整流桥KBPC1510的型号数字代表什么
Debezium series: MySQL tombstone event
Txt file virus
7-51 combination of two ordered linked list sequences
Debezium系列之:源码阅读之BinlogReader
The author of LinkedList said he didn't use LinkedList himself
行测-图形推理-1-汉字类
LeetCode144. Preorder traversal of binary tree
Redis cluster installation
Leetcode94. Middle order traversal of binary trees
Software test classification
Debezium series: source code reading snapshot reader
Signal feature extraction +lstm to realize gear reducer fault diagnosis -matlab code