Without Bit Manipulation Java


  • 0
    A

    Here is my code : Only downfall is it won't work if any number is 0 in array.

    public int singleNumber(int[] nums) {
            
            HashSet<Integer> hs = new HashSet<Integer>();
            
            for(int i = 0; i < nums.length; i++){
                hs.add(nums[i]);
            }
            
            int cube = 1;
            
            for(int x : hs){
                cube *= Math.pow(x,3);
            }
            
            int result = 0;
            
            for(int i = 0; i < nums.length; i++){
                cube /= nums[i];
            }
            
            
            
            return (int)Math.sqrt(cube);
        }
    

Log in to reply
 

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