Algorithm
-
[Leetcode] 350. Intersection of Two Arrays II 문제 풀이Algorithm/문제풀이 2021. 9. 17. 21:13
https://leetcode.com/problems/intersection-of-two-arrays-ii/ Intersection of Two Arrays II - 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 문제 내용 숫자 집합 2개가 주어지는 데 교집합을 구하면 된다. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] 문제 풀이 숫자 범위가 크지 않기 때문에 hash를 사용해서 풀었다. 1..
-
[Leetcode] 74. Search a 2D Matrix 문제 풀이Algorithm/문제풀이 2021. 9. 14. 22:59
https://leetcode.com/problems/search-a-2d-matrix/ Search a 2D Matrix - 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 문제 내용 2차원 배열이 정렬되어 있는 데 배열에서 target 찾기 Example 1: Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 Output: true 문제 풀이 binary search 2번 사용해서 풀었다...
-
[Leetcode] 33. Search in Rotated Sorted Array 문제 풀이Algorithm/문제풀이 2021. 9. 14. 22:30
https://leetcode.com/problems/search-in-rotated-sorted-array/ Search in Rotated Sorted Array - 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 문제 내용 정렬된 배열이 rotate되어 있다. rorate 되어 있는 배열에서 값 찾는 문제 Example 1: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 문제 풀이 binary search 로 풀..
-
[Leetcode] 34. Find First and Last Position of Element in Sorted Array 문제풀이Algorithm/문제풀이 2021. 9. 14. 22:21
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in Sorted Array - 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 문제 내용 정렬된 배열에서 target 숫자가 중복되서 반복되는데 첫번째 index와 마지막 index를 출력하는 문제 Example 1: Input: nums..
-
[Leetcode] 136. Single Number 문제 풀이Algorithm/문제풀이 2021. 9. 12. 21:30
https://leetcode.com/problems/single-number/ Single Number - 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 문제 내용 배열에 2개씩 숫자쌍이 있는데 혼자만 있는 숫자 찾기 Example 1: Input: nums = [2,2,1] Output: 1 문제 풀이 hash로 count 하는 단순한 방법은 공간 복잡도가 O(n) 만큼 든다. 공간 복잡도가 O(1) 만큼 하는 방법이 있다. xor 연산자를 활용하는 방법이다..
-
[Leetcode] 190. Reverse Bits 문제 풀이Algorithm/문제풀이 2021. 9. 12. 16:35
https://leetcode.com/problems/reverse-bits/ Reverse 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 문제 내용 주어진 bit를 reverse 하는 문제 Input: n = 00000010100101000001111010011100 Output: 964176192 (00111001011110000010100101000000) Explanation: The input binary string 000000101001..
-
[Leetcode] 191. Number of 1 Bits 문제 풀이Algorithm/문제풀이 2021. 9. 12. 16:17
https://leetcode.com/problems/number-of-1-bits/ 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 문제 내용 숫자 n이 있을 때, bit가 1인 갯수가 몇개인지 출력 Example 1: Input: n = 00000000000000000000000000001011 Output: 3 Explanation: The input binary string 000000000000000000000000000..
-
[Leetcode] 231. Power of Two 문제풀이Algorithm/문제풀이 2021. 9. 12. 16:10
https://leetcode.com/problems/power-of-two/ Power of Two - 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 문제 내용 주어진 정수 n이 2의 제곱인지 확인하는 문제 Example 1: Input: n = 1 Output: true Explanation: 2^0 = 1 문제 풀이 2의 제곱근을 생각하면 bit로 표현했을 때 1인 개수가 1개인 숫자이다. 처음에는 loop를 돌면서 bit개수를 세고 판단하려고 했으나 O(..