当前位置:网站首页>Array force buckle (continuously updated)
Array force buckle (continuously updated)
2022-07-24 04:29:00 【Bai Yanling】
List of articles
Sum of two numbers (7.21)

Execution time :3148ms
Write your own code :
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]
Official code :
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 []
Container for the most water (7.22 Medium difficulty )

The area depends on the short board .① Therefore, even if a longer plate is encountered when the long plate moves inward , The area of the rectangle will not change ; When you encounter a shorter board , The area will become smaller .② So you want the area to get bigger , Only the short board can move inward ( Because the moving direction is fixed ), Of course, it is also possible to make the area smaller , But only in this way can there be the possibility of making the area larger
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
Remove duplicate items from an ordered array (7.22 Simple )


reflection :
Or use double pointers
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
边栏推荐
- Alibaba Taobao Department interview question: how does redis realize inventory deduction and prevent oversold?
- 《论文复现》BiDAF代码实现过程(3)模型建立
- [hope to answer] the data cannot be synchronized correctly
- Send data 1010_ 1. The number of bytes passed by the sender
- Once svchost Troubleshooting of exe process occupying a large amount of network bandwidth
- The problem of monkeys eating peaches in classic exercises of C language
- [translation] chaos mesh moved to CNCF incubator
- Iqoo 10 series attacks originos original system to enhance mobile phone experience
- How does the trend chart of spot silver change?
- Privacy protection federal learning framework supporting most irregular users
猜你喜欢

C language classic exercises to write a program to find all the perfects within 1000.

Qt5.14_ Realize the free drag and drop combination function of vs2019 panel under mingw/msvc

How does the trend chart of spot silver change?

NFT除了买卖还能质押?

Leetcode 20 valid parentheses, 33 search rotation sort array, 88 merge two ordered arrays (nums1 length is m+n), 160 intersecting linked list, 54 spiral matrix, 415 character addition (cannot be direc

Go language series - synergy GMP introduction - with ByteDance interpolation

仿今日头条实时新闻微信小程序项目源码

(零八)Flask有手就行——数据库迁移Flask-Migrate

PostgreSQL guide -- inside exploration Chapter 1 database clusters, databases and data tables

C语言经典习题之编写一个程序,找出1000以内所有的完数。
随机推荐
C主机对IIC从来分别设置每足够的话,可下几位
Post it notes --46{hbuildx connect to night God simulator}
BGP notes (II)
CONDA common commands
Smart contract: release an erc20 token
Analyze the real-time development method of Bank of London
可以脱离设据生效这些都是控化部署能力,而后引如
dispatch_ Once's Secret
Pyth deinitialization averages on many machine decision boundaries, starting on the bus
LAN SDN hard core technology insider 21 Kang long regrets -- Specifications and restrictions (middle)
To -.---
Particle Designer: particle effect maker, which generates plist files and can be used normally in projects
一次 svchost.exe 进程占用大量网络带宽的排查
Parallel technology of Oracle
阿里淘系面试题:Redis 如何实现库存扣减操作和防止被超卖?
The judges of C language classic exercises score the highest and lowest to get an average score
[hope to answer] the data cannot be synchronized correctly
1.7.1 right and wrong problem (infix expression)
[untitled]
Traversal of binary tree