본문 바로가기

Algorithm/리트코드(LeetCode)16

[LeetCode] Two Sum II 목차 문제 numbers에서 두 개의 값을 뽑았을 때 target값이 되는 index1과 index2를 찾는 문제입니다. 예시 Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2]. Input: numbers = [2,3,4], target = 6 Output: [1,3] Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3]. Input: numbers = [-1,0], target = -1 Out.. 2024. 4. 10.
[LeetCode] Implement strStr() 목차 문제 B 문자열이 A 문자열에 있는지 체크하고, 있다면 최초로 등장한 인덱스를 반환하는 문제입니다. 예시 Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. Input: haystack = "leetcode", needle = "leeto" Output: -1 Explanation: "leeto" did not occur in "leetcode", so we return -1. 제약사항 1 int: n = len(haystack) m = len(needle) if n < m: ret.. 2024. 4. 10.
[LeetCode] Add Binary 목차 문제 이진수로 표현된 문자열 두 개를 더해 이진수로 표현된 문자열을 반환하는 문제입니다. 예시 Input: a = "11", b = "1" Output: "100" Input: a = "1010", b = "1011" Output: "10101" 제약조건 1 2024. 4. 8.
[LeetCode] Find Pivot Index 목차 문제 pivot 기준 왼쪽의 합과 오른쪽 합이 같아지는 pivot의 인덱스를 구하는 문제입니다. 예시 Input: nums = [1,7,3,6,5,6] Output: 3 Explanation: The pivot index is 3. Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11 Right sum = nums[4] + nums[5] = 5 + 6 = 11 Input: nums = [1,2,3] Output: -1 Explanation: There is no index that satisfies the conditions in the problem statement. Input: nums = [2,1,-1] Output: 0 Explanation: .. 2024. 4. 8.