首页 > 其他分享 >【LeetCode】27. 移除元素

【LeetCode】27. 移除元素

时间:2023-02-27 14:45:16浏览次数:37  
标签:27 nums int fast low 移除 LeetCode

移除指定元素

  • 时间复杂度 O(n)
  • 空间复杂度 O(1)
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int fast,low;
        for(fast = 0,low = 0; fast < nums.size(); fast++) {
            if(nums[fast] != val) {
                nums[low] = nums[fast];
                low++;
            }
        }
        return low;
    }
};

标签:27,nums,int,fast,low,移除,LeetCode
From: https://www.cnblogs.com/zjacky/p/17159608.html

相关文章

  • 【DFS】LeetCode 291. 单词规律 II
    题目链接291.单词规律II思路定义一个全局HashMap<Character,String>来存储映射关系,key为pattern的字符,value为str的子串。一开始,map中没有任何映射关系。......
  • 滴水 2.27 --事件
    第二个参数false会把已通知改为未通知true需要自己动手改为已通知第二个参数false会把已通知改为未通知点击查看代码 4、线程控制实验:只读形式的线程控制 ......
  • 数据结构刷题2023.02.27小记
    单循环链表A从表中任一结点出发都能扫描到整个链表B不再需要头指针了C在进行插入、删除操作时,能更好地保证链表不断开D已知某个结点的位置后,能够容易找到它的直接......
  • leetcode 862. 和至少为 K 的最短子数组
    一个双端单调队列:如果新加入的数比队列尾的数小,那么队列尾的数就可以丢去,这是因为如果未来的一个数能和队列尾的数满足条件,那么也一定可以和新加入的数满足条件。另外,如果......
  • python Numpy数组2.27
    #成员类型转换arr.astype(np.float_)#转换数组对象成员的类型为float,形状不变。#形状转换arr.resize(shape)#返回值是一个None,不能引用内部的属性arr.reshape(shape)#......
  • 20230227-华为防火墙双机热备配置
    一、双机热备主要涉及到三个协议:VRRP:两台防火墙共享一个虚拟IP(VRRP只支持两台防火墙,不支持多台),同一个VRRP组的两个接口通过协商确定主(master)和备(backup)状态,只有主状态的防......
  • SpringBoot移除liquibase
    SpringBoot移除liquibase1、spring自动加载配置的jar:org.springframework.boot:spring-boot-autoconfigure:2.3.2.RELEASE在spring-boot-autoconfigure包中查找spring.......
  • [LeetCode] 1333. Filter Restaurants by Vegan-Friendly, Price and Distance 餐厅过
    Giventhearray restaurants where restaurants[i]=[idi,ratingi,veganFriendlyi,pricei,distancei].Youhavetofiltertherestaurantsusingthreefilte......
  • 【DFS】LeetCode 52. N 皇后 II
    题目链接52.N皇后II思路与52.N皇后II一致代码classSolution{privateintresult;privateboolean[]mainDiag;privateboolean[]subDiag;......
  • 【DFS】LeetCode 51. N 皇后
    题目链接51.N皇后思路代码classSolution{privateList<List<String>>result;privateboolean[]mainDiagonal;privateboolean[]subDiagonal;......