leetcode 之Remove Duplicates from Sorted Array(1)
LeetCode from Array remove sorted Duplicates
2023-09-14 08:57:33 时间
删除数组中的重复元素并返回新数组的个数
思路:保留不同的元素即可。
1 int removeDeplicates(int A[], int n)
2 {
3 int index = 0;
4 for (int i = 0; i < n; i++)
5 {
6 if (A[index] != A[i])
7 {
8 A[index++] = A[i];
9 }
10 }
11
12 return index + 1;
13 }
相关文章
- Java实现 LeetCode 778 水位上升的泳池中游泳(二分+DFS)
- Java实现 LeetCode 676 实现一个魔法字典(暴力)
- Java实现 LeetCode 476 数字的补数
- Java实现 LeetCode 461 汉明距离
- Java实现 LeetCode 268 缺失数字
- Java实现 LeetCode 41 缺失的第一个正数
- [Javascript] Filter out Duplicates from Flat JavaScript Array with array.filter / reduce / Set
- LeetCode:105_Construct Binary Tree from Preorder and Inorder Traversal | 根据前序和中序遍历构建二叉树 | Medium
- 【LeetCode算法-26】Remove Duplicates from Sorted Array
- [ES6] Converting an array-like object into an Array with Array.from()
- [LeetCode] Find Median from Data Stream
- [LeetCode] Find Peak Element
- 【数组&双指针】leetcode 234. 回文链表【简单】
- LeetCode-462. 最少移动次数使数组元素相等 II【排序】
- leetcode 刷题之路 66 Path Sum II
- leetcode 题解 || Remove Nth Node From End of List 问题
- [LeetCode] 83. Remove Duplicates from Sorted List ☆(从有序链表中删除重复项)
- leetcode 141. 环形链表 js 实现
- 73_leetcode_Construct Binary Tree from Inorder and Postorder Traversal
- leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
- LeetCode 423. Reconstruct Original Digits from English——学会观察,贪心思路
- 【Leetcode刷题Python】 LeetCode 2038. 如果相邻两个颜色均相同则删除当前颜色