Given an array of integers, every element appears twice except for one. Find that single one.
来源:互联网 发布:office2016破解软件 编辑:程序博客网 时间:2024/05/01 06:37
方法一:
import java.util.Arrays;
public class Solution {public int singleNumber(int[] A) {
Arrays.sort(A);
int i=0;
for(i=0;i<A.length;i++){
if(i+1<A.length&&A[i]==A[i+1])
i=i+1;
else
break;
}
return A[i];
}
}
方法二:
import java.util.Arrays;
public class Solution {
public int singleNumber(int[] A) {
int a=0;
for(int i=0;i<A.length;i++)
a=a^A[i];
return a;
}
}
0 0
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of size n, find the majority element. The majority element is the element that appear
- given an array of integers Find the index of values that satisfy A+B = C + D
- Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missi
- Find that single one.(linear runtime complexity0
- 【LeetCode】169. Majority Element Majority Element Given an array of size n, find the majority eleme
- Given an array of integers, return indices of the two numbers such that they add up to a specific ta
- CareerCup Given an array of (unsorted) integers, arrange them such that a < b > c < d > e... etc.
- 代码面试题:Find the first element in a given string A that also appears in another given string B
- Find the maxest element of an array
- Given an array of ages (integers) sorted lowest to highest, output the number of occurrences for eac
- Find the element that appears once
- Find the element that appears once
- CareerCup Given an array having positive integers, find a subarray which adds to a given number
- Given an array of integers, sort the array according to frequency of elements
- ListviewFilter 对A-Z排序 过滤 搜索功能(为github高手所做)
- Intellij IDEA 配置Tomact
- ant删除文件操作
- sql----改写 in ,exists,not in ,not exists
- Linux系统对IO端口和IO内存的管理
- Given an array of integers, every element appears twice except for one. Find that single one.
- 使用共用体存储各类型数据到EEPROM
- 安卓开发sdk选择和兼容问题
- spring的controller默认是单例还是多例
- UVA291_The House Of Santa Claus(DFS)
- Android平台上做一个完美的音乐频谱--Music Audio Glow
- opencv操作每个像素
- [LeetCode]Longest Consecutive Sequence
- Unreal SDK 游戏开发从入门到精通视频教程