Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- dacon
- ubuntu
- 데이콘
- AI 경진대회
- 편스토랑
- Baekjoon
- PYTHON
- 코로나19
- 더현대서울 맛집
- 백준
- 자연어처리
- programmers
- Kaggle
- hackerrank
- 캐치카페
- Git
- 금융문자분석경진대회
- Docker
- ChatGPT
- 프로그래머스
- 파이썬
- leetcode
- 프로그래머스 파이썬
- 편스토랑 우승상품
- gs25
- 맥북
- github
- Real or Not? NLP with Disaster Tweets
- 우분투
- SW Expert Academy
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1486. XOR Operation in an Array (Python) 본문
728x90
반응형
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.
Example 2:
Input: n = 4, start = 3
Output: 8
Explanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.
Example 3:
Input: n = 1, start = 7
Output: 7
Example 4:
Input: n = 10, start = 5
Output: 2
Constraints:
- 1 <= n <= 1000
- 0 <= start <= 1000
- n == nums.length
Solution
class Solution:
def xorOperation(self, n: int, start: int) -> int:
answer = 0
for i in range(n):
answer = answer ^ start + 2 * i
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 328. Odd Even Linked List (Python) (0) | 2021.01.30 |
---|---|
[leetCode] 941. Valid Mountain Array (Python) (0) | 2021.01.29 |
[leetCode] 476. Number Complement (Python) (0) | 2021.01.27 |
[leetCode] 784. Letter Case Permutation (Python) (0) | 2021.01.26 |
[leetCode] 367. Valid Perfect Square (Python) (0) | 2021.01.25 |
Comments