IT 개발자_S

[코딜리티]OddOccurrencesInArray 본문

IT/알고리즘_JAVA

[코딜리티]OddOccurrencesInArray

Soso12 2020. 5. 9. 16:36
반응형

1. 배열을 입력받아

2.홀수의 pair 가 있는지 없는 숫자의 값을 return 해주는 알고리즘이다

3. 이중for문을 만들어 답을 찾을경우 performance 이슈로 점수를 받지 못하여

4. 구글링을 통해 xor 방법을 찾아 해결할 수 있었음

5. xor 인경우 1,1 =0 1,0 =1 같은 비트마스크인경우 0을 반환하기 때문에 해당 로직을 구성할 수 있었음.

// you can also use imports, for example:
// import java.util.*;

// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");

class Solution {
    public int solution(int[] A) {
        // write your code in Java SE 8
    


        int result = 0;

        for (int i : A){
          

          result ^= i;
        //  System.out.println("i : " + i +" result : " +result)  ;
            
        } 

        return result;


     
    }
}
반응형

'IT > 알고리즘_JAVA' 카테고리의 다른 글

[코딜리티] TapeEquilibrium  (0) 2020.05.10
[코딜리티]PermMissingElem  (0) 2020.05.10
[코딜리티]Frog_jump  (0) 2020.05.10
[코딜리티]CyclicRotation  (0) 2020.05.09
[코딜리티] Binary Gap  (0) 2020.05.09
Comments