Simple JAVA solution


  • -5
    A
    public class Solution {
        public int singleNumber(int[] nums) {
            Arrays.sort(nums);
            int result = nums[0];
            for (int i=1; i<nums.length; i++) {
                if (nums[i] == result) {
                    i += 2;
                    result = nums[i];
            }
        }
        return result;
    }

  • 1
    E

    "Your algorithm should have a linear runtime complexity."


Log in to reply
 

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