/** * 找到数组中两个不同的值 * / public static void main(String[] args) { int[] arr={2,2,1,1,3,4}; int eo = eh(arr); int offset = getOffset(eo); int eo1 = 0; for(int i:arr){ if(((i>>offset)&1)==1)continue; eo1 ^= i; } System.out.println((eo^eo1) +" "+eo1); } public static int eh(int[] n){ int eo = 0; for(int i:n){ eo ^= i; } return eo; } public static int getOffset(int n){ int i = 0; while((n&1)!=1){ n = n>>1; i++; } return i; }
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦