LeetCode3 [leetcode] 바이너리 - 191번 Number of 1 Bits (Java) 문제링크 Number of 1 Bits - 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 접근한 방법 바이너리 풀이방법 먼저, signed와 unsigned의 개념을 알아보자. signed - C/C++ 프로그램 언어에서 정수형 변수 중 부호를 갖는 변수를 선언한다. 정수형 중 음수는 2의 보수 체계를 사용하므로 이 키워드에 의해 부호를 사용할 수 있도록 변수 선언할 수 있다. 그러나 정수형의 변수에서 unsigned가 없으면 음수를 사용할 수 있는 부호를 갖는.. 2021. 10. 31. [leetcode] 배열 - 238번 Product Of ArrayExceptSelf (Java) 문제링크 Product of Array Except Self - 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 접근한 방법 배열 풀이방법 처음에 이중 반복문으로 풀어서 시간초과가 나왔다. 따라서, 블로그를 참조하여 이해할 수 있었다. 소스코드 package leetcode.array; import java.util.EnumSet; public class Q238_ProductOfArrayExceptSelf { public static int[] productEx.. 2021. 10. 30. [leetcode] 바이너리 - 371번 Sum of Two Integers (Java) 문제링크 Sum of Two Integers - 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 접근한 방법 비트연산 풀이방법 XOR와 AND연산을 이용한다. AND연산의 경우 연산을 한 후에 왼쪽으로 시프트를 한다. a와 b의 XOR, AND 및 왼쪽으로 시프트 연산의 결과를 놓고 또 연산을 반복하여 둘 중 하나의 연산 결과가 0이 나올 때까지 반복한다. e.g. 소스코드 작성 방법 getSum 메소드에 인자를 a와 b로 받는다. a와 b의 xor 연산을 한다... 2021. 10. 16. 이전 1 다음 반응형