my solution same to yours, but don't know why there shows wrong answer


  • 0
    Z

    Re: [My Solution : Time O(n)](Space O(1))
    class Solution {
    public int removeDuplicates(int[] nums) {
    if(nums.length == 0)
    return 0;
    int len = nums.length;
    int num = 1;
    int i = 0;
    while(i < (len-1)){
    if(nums[i] < nums[i + 1])
    {
    num++;
    }
    i++;
    }
    return num;
    }
    }


Log in to reply
 

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