Java code cost O(c*N) time O(0) space, but why this code cost 15-18 ms?


  • 0
    G

    public class Solution {
    public List<Integer> findDisappearedNumbers(int[] nums) {
    List<Integer> list = new ArrayList<Integer>();
    int length = nums.length,temp = length+1;;
    for(int i=0;i<length;i++){
    nums[(nums[i]%temp)-1]+= temp;
    }
    for(int i=0;i<length;i++){
    if(nums[i]<temp){
    list.add(i+1);
    }
    }
    return list;
    }
    }


Log in to reply
 

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