Bit Manipulation: Lonely Integer

Sort by

recency

|

162 Discussions

|

  • + 0 comments

    public class Solution {

    // Complete the findLonely function below.
    static int findLonely(List<Integer> arr) {
        int num=0;
       for(int i:arr){
           num=num^i;
       }return num;
    
    }
    
  • + 0 comments

    Brute force C++ Code || Bit Manipulation

    int findLonely(vector<int> arr) {
        int ans = 0;
        for(int i=0;i<arr.size();i++)
        {
            ans = ans ^ arr[i];
        }
        return ans;
    }
    
  • + 0 comments

    Tiny Ruby solution:

    def find_lonely(arr)
      arr.inject(&:^)
    end
    
    _n = gets.to_i
    arr = gets.split.map(&:to_i)
    puts find_lonely(arr)
    
  • + 0 comments

    Another way of doing the code: def findLonely(arr): array = list(set(arr)) for i in range(len(array)): if arr.count(array[i]) !=2: return array[i]

  • + 0 comments

    Another way of doing the code: def findLonely(arr): array = list(set(arr)) for i in range(len(array)): if arr.count(array[i]) !=2: return array[i]