Is using Arrays.sort(nums1) cheating?


  • 0
    K

    Or are we supposed to write the sorting steps manually?

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        n=n-1;
    	while (n>=0)
    		nums1[m++]=nums2[n--];
    	Arrays.sort(nums1);        
        }

  • 0
    S

    The point of these problems is not to check how well you know the in-built methods but to test your ability to solve problems. So I dont think you are allowed to use the sort method.


  • 0
    D

    Its not cheating, but it is bad. You are using an O(n log n) solution when there are easy O(n) solutions.


Log in to reply
 

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