当前位置:网站首页>数组力扣(持续更新)
数组力扣(持续更新)
2022-07-24 04:25:00 【白炎灵】
两数之和(7.21)

执行用时:3148ms
自己写的代码:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
n = len(nums)
for i in range(n):
for j in range(i+1,n):
if nums[i] + nums[j] == target:
return [i,j]
官方代码:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hashtable = dict()
for i, num in enumerate(nums):
if target - num in hashtable:
return [hashtable[target - num], i]
hashtable[nums[i]] = i
return []
盛最多水的容器(7.22 难度中等)

面积取决于短板。①因此即使长板往内移动时遇到更长的板,矩形的面积也不会改变;遇到更短的板时,面积会变小。②因此想要面积变大,只能让短板往内移动(因为移动方向固定了),当然也有可能让面积变得更小,但只有这样才存在让面积变大的可能性
class Solution:
def maxArea(self, height: List[int]) -> int:
l, r = 0, len(height) - 1
ans = 0
while l < r:
area = min(height[l], height[r]) * (r - l)
ans = max(ans, area)
if height[l] <= height[r]:
l += 1
else:
r -= 1
return ans
删除有序数组中的重复项 (7.22 简单)


思考:
还是利用双指针
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
n = len(nums)
fast = slow = 1
while fast < n:
if nums[fast] != nums[fast - 1]:
nums[slow] = nums[fast]
slow += 1
fast += 1
return slow
边栏推荐
- The second anniversary of open source, opengauss Developer Day 2022 full highlights review!
- Chapter III query processing of PostgreSQL Guide - Insider exploration
- Introduction to the application fields and functions of bank virtual human technology
- Where is the difficulty in attracting investment in the park? Inventory of difficulties and difficulties in attracting investment in industrial parks
- LAN SDN technology hard core insider 9 from software overlay to hardware overlay
- Ship test / IMO a.799 (19) incombustibility test of marine structural materials
- 高频小信号谐振放大器设计-课程设计Multisim仿真
- C语言经典习题之评委打分去掉最高最低求平均分
- 短视频本地生活版块,有哪些新的机会存在?
- Good performance and reliability. The parameter that initiates writing IIC co type code and is -4
猜你喜欢

Go language series - synergy GMP introduction - with ByteDance interpolation

postgresql源码学习(32)—— 检查点④-核心函数CreateCheckPoint

高频小信号谐振放大器设计-课程设计Multisim仿真

Chapter III query processing of PostgreSQL Guide - Insider exploration

硬件知识3--IIC协议

mysql服务1主2从,主主,MHA配置详细步骤

What new opportunities exist in the short video local life section?

Post it notes --46{hbuildx connect to night God simulator}

Iqoo 10 series attacks originos original system to enhance mobile phone experience

Shell语法(一)
随机推荐
er系统,在 Lin应答位时,数,成功开r Com更
【C语言】程序环境和预处理操作
Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用
IP second experiment mGRE OSPF
The pit trodden by real people tells you to avoid the 10 mistakes often made in automated testing
"Wei Lai Cup" 2022 Niuke summer multi school training camp 1 (summary of some topics)
可能有点用的冷知识
[novice] develop a tab component that is easy to expand by hand
The second anniversary of opengauss' open source, cracking the pain point of database ecology
Up sampling method (deconvolution, interpolation, anti pooling)
Ambire wallet opens twitter spaces series
如何用STATA进行chowtest
C主机对IIC从来分别设置每足够的话,可下几位
Function application of 4G transmission module
The amount of training data is not only applicable to.Z, according to the receiver's view of the number
What if the references in the word sent by others are {} in such a garbled format
The C host is always set separately for IIC. If enough, the next few bits can be set
Alibaba Taobao Department interview question: how does redis realize inventory deduction and prevent oversold?
PMIX ERROR: ERROR in file gds_ ds12_ lock_ pthread.c
Label smoothing