[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) 027. Remove Element (Easy)链接:题目:https://oj.leetcode.com/problems/remove-element/ 题意:删除1个数组里值为 elem 的所有数。 分析:用两个指针,1个为可放位置的指针,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;
}
};
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |