leetcode80[medium]--Remove Duplicates from Sorted Array II

難度:medium

Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?

For example,
Given sorted array nums = [1,1,1,2,2,3],

Your function should return length = 5, with the first five elements of nums being 1122 and 3. It doesn't matter what you leave beyond the new length.

思路: 刪除給定list裏面重複超過兩次以上的element,最後返回list的最終長度。

           此類題肯定是要用到hashtable,key對應的value是該數字出現的次數,當出現的次數超過兩次,(注意順序)先將value降至2,再刪除原list中的element,最後修改while語句中的n。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章