1.读写文件
/**
* 使用文件输入流读取原文件,使用文件输出流往新文件里写
* 使用块读写形式将原文件数据写入到新文件完成复制操作
*/
public void copy(String from,String to){
FileInputStream fis=new FileInputStream(from);
FileOutputStream fos=new FileOutputStream(to);
byte[] data=new byte[1024*10];
int len=-1;
while(len=fis.read(data)!=-1){
fos.write(data,0,len);
}
fis.close();
fos.close();
}
2.找出数组中只出现一次的两个数(空间O(1),时间O(n))
public int[] fun(int[] nums){
int e0,e1;
for(int temp:nums){
e0^=temp;//A^B
}
int k=e0&(~e0+1);//得到A^B中为1那一位
for(int temp:nums){
if((k&temp)!=0){//遍历A或B中一个和其他重复的
e1^=temp;//最后等于A或B中一个
}
}
int e2=e0^e1;
return e1<e2 ? new int[]{e1,e2} : new int[]{e2,e1};
}