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
- programmers
- 더현대서울 맛집
- 데이콘
- 코로나19
- 캐치카페
- SW Expert Academy
- AI 경진대회
- 프로그래머스
- 우분투
- 백준
- Docker
- Real or Not? NLP with Disaster Tweets
- ubuntu
- Baekjoon
- 편스토랑
- github
- 자연어처리
- dacon
- Kaggle
- gs25
- PYTHON
- 파이썬
- hackerrank
- 프로그래머스 파이썬
- 금융문자분석경진대회
- leetcode
- 편스토랑 우승상품
- Git
- 맥북
- ChatGPT
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1009. Complement of Base 10 Integer (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 1009. Complement of Base 10 Integer (Python)
솜씨좋은장씨 2021. 1. 31. 00:07728x90
반응형
Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on. Note that except for N = 0, there are no leading zeroes in any binary representation.
The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to a 1. For example, the complement of "101" in binary is "010" in binary.
For a given number N in base-10, return the complement of it's binary representation as a base-10 integer.
Example 1:
Input: 5
Output: 2
Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.
Example 2:
Input: 7
Output: 0
Explanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.
Example 3:
Input: 10
Output: 5
Explanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.
Note:
- 0 <= N < 10^9
- This question is the same as 476: https://leetcode.com/problems/number-complement/
Solution
class Solution:
def bitwiseComplement(self, N: int) -> int:
return int("".join(list(map(str, [1-num for num in list(map(int, list(str(bin(N))[2:])))]))), 2)
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 162. Find Peak Element (Python) (0) | 2021.02.02 |
---|---|
[leetCode] 1232. Check If It Is a Straight Line (Python) (2) | 2021.02.01 |
[leetCode] 328. Odd Even Linked List (Python) (0) | 2021.01.30 |
[leetCode] 941. Valid Mountain Array (Python) (0) | 2021.01.29 |
[leetCode] 1486. XOR Operation in an Array (Python) (0) | 2021.01.28 |
Comments