当前位置:网站首页>Problem solving -- question 283 of leetcode question bank
Problem solving -- question 283 of leetcode question bank
2022-07-24 10:33:00 【Carefully programmed purple shirt Dragon King】
One .Leetcode Item bank No 283 Title
Two . Idea of problem solving
This question is the same as the previous one 26. Remove duplicate items from an ordered array and 27. Remove elements The two problems can be solved relatively conveniently by using the double pointer solution . Slow pointer update new array (0 All at the end ), Fast pointer traverses array elements , Look for non-zero elements
3、 ... and . Double pointer code
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
slow,fast=0,0
while fast<=len(nums)-1:
if nums[fast] !=0:
nums[slow]=nums[fast]
slow+=1
fast+=1
for i in range(slow,fast):
nums[i]=0Four . Code parsing
- The first is the very conventional double pointer problem solving template , Get a new array containing all non-zero elements
- Secondly, the remaining parts become zero
边栏推荐
- 563页(30万字)智慧化工园区(一期)总体设计方案
- 2022, will lead the implementation of operation and maintenance priority strategy
- ffmpeg花屏解决(修改源码,丢弃不完整帧)
- Association Rules -- July 10, 2022
- The role of glpushmatrix and glpopmatrix
- Erlang studies abroad
- Ffmpeg splash screen solution (modify the source code and discard incomplete frames)
- Sentinel implements the persistence of pull pattern rules
- 高精尖中心论文入选国际顶会ACL 2022,进一步拓展长安链隐私计算能力
- JSON tutorial [easy to understand]
猜你喜欢

MySQL - unique index

MySQL 数据库 JDBC编程

MySQL - 普通索引

Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions

2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1

MySQL - 索引的隐藏和删除

Golang migrate is easy to use

Sentinel 实现 pull 模式规则持久化

Association Rules -- July 10, 2022

Create a vertical seekbar from scratch
随机推荐
多表查询之子查询_单行单列情况
Erlang learning 02
Binary original code, inverse code, complement code
zoj-Swordfish-2022-5-6
JS function call download file link
zoj1137+作业1--2022年5月28日
Sentinel 三种流控模式
New:Bryntum Grid 5.1.0 Crack
Dr. water 3
Websocket 协议解读-RFC6455
MySQL - normal index
MySQL - 更新表中的数据记录
MySQL - 多列索引
In depth analysis of common cross end technology stacks of app
Mysql database JDBC programming
数组元素移除问题
Uniapp calendar component
Analysis of Kube proxy IPVS mode
Arduino + AD9833 波形发生器
Ffmpeg splash screen solution (modify the source code and discard incomplete frames)