Java 348ms so happy.


  • 0
    M
    /**
     * Created by tianyuji on 24/8/2015.
     */
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums == null || nums.length == 0) {
                return 0;
            }
            int writePoint = 0;
            int readPoint = 1;
            while (readPoint < nums.length) {
                if (nums[readPoint] > nums[writePoint]) {
                    nums[writePoint + 1] = nums[readPoint];
                    writePoint++;
                    readPoint++;
                } else {
                    readPoint++;
                }
            }
            return writePoint + 1;
        }
    }

  • 0

    Can be compressed to nums[++writePoint] = nums[readPoint++];


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.