Algorithm/Codility

Lesson2-1. OddOccurrencesInArray

hamaganatanadda 2019. 6. 20. 22:31

L : https://app.codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/

 

Q : 배열을 받아서 배열값안에 숫자가 홀수개로 있는 항목을 찾으면 되는 문제. 

 

A : 구글에 참고하여 XOR 연산으로 처리. 

잘 모르는 부분이라 공부

 

[Delphi]

1
2
3
4
5
6
7
8
9
10
11
12
function solution(A: array of longint; N: longint): longint;
var
  ii, iResult : Longint;
begin
  iResult := 0;
  for ii := low(A) to high(A) do
  begin
    iResult := iResult xor A[ii];
  end;
  
  exit(iResult);
end;
cs

 

※ 수정할 부분이 있으면 알려주세요. 로직 짠 후 구글링으로도 참고합니다. 

'Algorithm > Codility' 카테고리의 다른 글

Lesson3-3. TapeEquilibrium  (0) 2019.06.22
Lesson3-2. PermMissingElem  (0) 2019.06.20
Lesson3-1. FrogJmp  (0) 2019.06.20
Lesson2-2. CyclicRotation  (0) 2019.06.20
Lesson1. BinaryGap  (0) 2019.06.19