LinCode落单的数
生活随笔
收集整理的這篇文章主要介紹了
LinCode落单的数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
easy?落單的數 查看執行結果?
60% 通過給出2*n + 1?個的數字,除當中一個數字之外其它每一個數字均出現兩次。找到這個數字。
給出?[1,2,2,1,3,4,3]。返回 4
挑戰一次遍歷,常數級的額外空間復雜度
位運算
class Solution { public:/*** @param A: Array of integers.* return: The single number.*/int singleNumber(vector<int> &A) {// write your code hereint a =0;for (auto x :A){a ^=x;}return a;} };暴力求解 class Solution { public:/*** @param A: Array of integers.* return: The single number.*/int singleNumber(vector<int> &A) {// write your code herefor (auto x:A){int i = 0;for (auto y:A){if(x == y){++i;}}if (1==i){return x;}}} };
轉載于:https://www.cnblogs.com/lxjshuju/p/6769111.html
總結
以上是生活随笔為你收集整理的LinCode落单的数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Examplematcher 模糊查询需
- 下一篇: CF-798B