# leetcode 026. Remove Duplicates from Sorted Array [leetcode 026. Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) (<font color="#00AF9B"> Easy</font> 通過率: 52.3%) ## 限制條件 <ul> <li>1 <= nums.length <= 3 * 10^4</li> <li>-100 <= nums[i] <= 100</li> <li>nums is sorted in non-decreasing order.</li> </ul> ### 解法 1 簡單的暴力解,好像也不用解釋啥 - 時間複雜度: O(n) - 空間複雜度: O(1) ```cpp!= class Solution { public: int removeDuplicates(vector<int>& nums) { int result = 1; for(int i = nums.size()-1;i>0;i--) { if(nums[i] == nums[i-1]) { nums.erase(nums.begin()+i-1); } else { result++; } } return result; } }; ``` </int>
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up