題庫
00:00

13. Remove Duplicates from Sorted Array

簡單雙指標MicrosoftGoogle

Given an array nums sorted in non-decreasing order, remove duplicates in place so each element appears once, and return the new length.

範例 1:

輸入: nums = [1,1,2]
輸出: 2

範例 2:

輸入: nums = [0,0,1,1,1,2,2,3,3,4]
輸出: 5

限制條件:

  • 1 <= nums.length <= 3 * 10^4
  • nums is sorted in non-decreasing order.
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄