Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =[1,1,1,2,2,3] ,
Given sorted array nums =
Your function should return length = 5 , with the first five elements of nums being 1 , 1 , 2 , 2 and 3 . It doesn't matter what you leave beyond the new length.
<Solution>這題是 Remove Duplicates from Sorted Array 的衍生題
這次多了可以指定每個數字能重覆幾次
思考方式還是一樣,只是多了一個 counter 來滿足題目需求
code 如下
c++
kotlin
沒有留言:
張貼留言