IT/알고리즘
12] Leetcode 1486. XOR Operation in an Array
깻잎쌈
2020. 6. 24. 21:53
반응형
배타적 논리합, XOR 연산에 관한 문제다.
XOR Operation in an Array - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
초기값만 start로 해주고 나머지는 이어서 고대로 해주면 된다.
class Solution {
public:
int xorOperation(int n, int start) {
int ans = start;
for(int i = 1;i<n;i++)
ans= ans^(start+2*i);
return ans;
}
};
C++ - ^ - 비트 XOR (배타적 논리합) | c++ Tutorial
c++ documentation: ^ - 비트 XOR (배타적 논리합)
riptutorial.com
반응형