일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 입원
- 용인세브란스병원
- 동위원소치료
- MYSQL
- 정렬 알고리즘
- 프로그래머스
- 전이
- 저요오드식
- 입원준비
- 갑상선암용인세브란스
- Android
- 안드로이드
- 이직 준비
- leetcode
- 임파선전이
- 림프절전이
- 폐CT
- 맛집
- 객체
- 갑상선암
- 경력 개발자
- 방사성동위원소치료
- 수술
- firebase
- 카페
- java
- 방사성 동위원소 치료
- 백준알고리즘
- 알고리즘
- 월간 코드 챌린지 시즌1
Archives
- Today
- Total
새우버거의 개발 블로그
[Java] LeetCode 1486 : XOR Operation in an Array 본문
LeetCode # 1486
Given an integer n and an integer start.
Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length.
Return the bitwise XOR of all elements of nums.
Example 1:
Input: n = 5, start = 0
Output: 8
Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8. Where "^" corresponds to bitwise XOR operator.
Note:
- 1 <= n <= 1000
- 0 <= start <= 1000
- n == nums.length
Solution #1 (0ms)
class Solution {
public int xorOperation(int n, int start) {
int answer = 0;
for (int i = 0; i < n; i++) {
answer ^= (start + i * 2);
}
return answer;
}
}
Result #1
More Algorithm!
👇👇
github.com/ggujangi/ggu.leet-code
ggujangi/ggu.leet-code
LeetCode, Java. Contribute to ggujangi/ggu.leet-code development by creating an account on GitHub.
github.com
출처 : leetCode
'알고리즘 > LeetCode' 카테고리의 다른 글
[Java] LeetCode 290 : Word Pattern (0) | 2021.04.17 |
---|---|
[Java] LeetCode 914 : X of a Kind in a Deck of Cards (0) | 2021.04.17 |
[Java] LeetCode 977 : Squares of a Sorted Array (0) | 2021.03.30 |
[Java] LeetCode 1295 : Find Numbers with Even Number of Digits (0) | 2021.03.30 |
[Java] LeetCode 485 : Max Consecutive Ones (0) | 2021.03.30 |