One line Java8 code that will surprise the Interviewer


  • 0
    P
    1. It is the XOR operation.
    2. We combine Java 8 lambda expression and stream operation.
    public int singleNumber(int[] nums) {
            return Arrays.stream(nums).reduce(0, (x, y)->x ^y);
        }
    

Log in to reply
 

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