136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

题目含义:给定的数组中,每个数字出现两次,只有一个数字出现了一次,找出这个数字

1     public int singleNumber(int[] nums) {
2         int result = 0;
3         for (int i = 0; i < nums.length; i++) {
4             result ^= nums[i];
5         }
6         return result;        
7     }

 

posted @ 2017-10-23 21:21  daniel456  阅读(94)  评论(0编辑  收藏  举报