加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

[LeetCode] 027. Remove Element (Easy) (C++)

发布时间:2020-12-13 20:16:28 所属栏目:PHP教程 来源:网络整理
导读:索引:[LeetCode] Leetcode 题解索引 (C/Java/Python/Sql) Github: https://github.com/illuz/leetcode 027. Remove Element (Easy) 链接 : 题目:https://oj.leetcode.com/problems/remove-element/ 代码(github):https://github.com/illuz/leetcode 题意

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql)
Github: https://github.com/illuz/leetcode


027. Remove Element (Easy)

链接

题目:https://oj.leetcode.com/problems/remove-element/
代码(github):https://github.com/illuz/leetcode

题意

删除1个数组里值为 elem 的所有数。

分析

用两个指针,1个为可放位置的指针,1个为扫描指针。
由于不难,Java 和 Python 的做法都和 C++ 1样,这里就不给出了。

代码

C++:


class Solution { public: int removeElement(int A[],int n,int elem) { int ret = 0; for (int i = 0; i < n; i++) if (A[i] != elem) A[ret++] = A[i]; return ret; } };

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读