bit 3

[LeetCode] 338. Counting Bits

338. Counting BitsLeetCode Given an integer n, return an array ans of length n + 1 such that for each i (0 정수 n이 주어졌을 때, 0 ExampleInput: n = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 --> 0 1 --> 1 2 --> 10 3 --> 11 4 --> 100 5 --> 1011. 문제 요구사항 분석0 ~ n 까지 이진수로 표현한 후, 1의 개수 구하기 2. 접근 전략파이썬은 bin이라고 제공되고 있는 함수가 있기 때문에 파이썬으로 1차 구현 후, 자바..

[LeetCode] 191. Number of 1 Bits

191. Number of 1 BitsLeetCodeGiven a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).양의 정수 n이 주어졌을 때, 해당 숫자의 이진수 표현에서 '설정된 비트(set bits, 값이 1인 비트)'의 개수를 반환하는 함수를 작성하세요 (이는 해밍 가중치(Hamming weight)라고도 부릅니다). ExampleInput: n = 11Output: 3Explanation:The input binary string 1011 has a total of three set bits.Input..

[LeetCode] 371. Sum of Two Integers (비트 연산자)

371. Sum of Two IntegersLeetCodeGiven two integers a and b, return the sum of the two integers without using the operators + and -.두 정수 a와 b가 주어졌을 때, +와 - 연산자를 사용하지 않고 두 정수의 합을 반환하세요. ExampleInput: a = 1, b = 2 Output: 3Input: a = 2, b = 3 Output: 5 1. 문제 요구사항 분석+ 연산자와 - 연산자를 사용하지 않고 두 정수의 합 계산하기 2. 접근 전략되게 쉽다고 생각하고 왜 medium 문제이지? 하고 문제를 다시 봤더니... + 와 - 연산자를 사용하지 않고라니...곱하기, 나누기로는 절대 안 되고 ... 컴퓨..

728x90
반응형