
알고리즘/문제풀이 2022. 7. 9.
[LeetCode] 88. Merge Sorted Array (Easy) 풀이
❓ 문제 You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. 내림차순으로 정렬된 두 개의 정수형 배열인 nums1 및 nums2와 nums1과 nums2의 element 수를 나타내는 두 개의 정수인 m, n가 주어진다. Merge nums1 and nums2 into a single array sorted in non-decreasing order. nums1과 nums2를 내림차순으로 정렬된 하나의 배열로 병합하려고 한다. The final..

알고리즘/문제풀이 2022. 7. 6.
[LeetCode] 70. Climbing Stairs (Easy) 풀이
❓ 문제 You are climbing a staircase. It takes n steps to reach the top. 계단을 올라가야한다. 계단 끝에 도달하기 위해 n 계단을 밟아야한다. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 한번에 1계단 또는 2계단만 올라갈 수 있다. 계단 마지막으로 올라가기 위해서 중복 없이 얼마나 많은 경우의 수가 있는가? Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Exampl..

알고리즘/문제풀이 2022. 6. 20.
[LeetCode] 69. Sqrt(x) (Easy) 풀이
❓ 문제 Given a non-negative integer x x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. pow(x, 0.5) or x ** 0.5. 음이 아닌 정수 x x가 주어진다. 리턴타입이 정수형이기 때문에 소수점 이하 자리수는 잘리고 오직 결과의 정수부분만 리턴한다. pow(x, 0.5) or x ** 0.5. Example 1: Input: x = 4 Output: 2 Example 2: Input: x = 8 Output: 2 Explanation: The square root of 8 is 2.82842....

알고리즘/문제풀이 2022. 6. 20.
[LeetCode] 66. Plus One (Easy) 풀이
❓ 문제 You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits. 정수 배열 자릿수로 표현되는 큰 정수가 주어진다. 여기서 각 자릿수[i]는 정수의 i번째 ..

알고리즘/문제풀이 2022. 3. 16.
[LeetCode] 20. Valid Parentheses (Easy) 풀이
❓ 문제 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. '(', ')', '{', '}', '[' 및 ']' 문자만을 포함하는 문자열이 주어지면 입력 문자열이 유효한지 확인한다. 문자열이 유효한 경우 : 열린 괄호는 반드시 같은 타입의 괄호로 닫혀야 한다. 열린 괄호는 반드시 올바른 순서로 닫..

알고리즘/문제풀이 2022. 3. 16.
[LeetCode] 14. Longest Common Prefix (Easy) 풀이
❓ 문제 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". 문자열 배열 중에서 가장 긴 공통 접두사 문자열을 찾는 함수를 작성하자. 공통된 접두사가 없으면 빈 문자열 ""을 반환한다. Example 1: Input: strs = ["flower","flow","flight"] Output: "fl" Example 2: Input: strs = ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input..

알고리즘/문제풀이 2022. 3. 14.
[LeetCode] 13. Roman to Integer (Easy) 풀이
❓ 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. 로마 숫자는 I, V, X, L, C, D, M의 7가지 기호로 표시된다. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written..

알고리즘/문제풀이 2022. 3. 11.
[LeetCode] 9. Palindrome Number (Easy) 풀이
❓ 문제 Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not. 정수 x가 주어졌을 때, x가 회문이면 true를 반환한다. 앞으로 읽었을 때와 뒤로 읽었을 때 같을 경우 해당 정수를 회문이라고 한다. 예를 들어, 121은 회문이지만 123은 회문이 아니다. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right..

알고리즘/문제풀이 2022. 3. 11.
[LeetCode] 1. Two Sum (Easy) 풀이
❓ 문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. 정수로 이루어진 배열과 정수인 target이 주어지면, 두 숫자의 합이 target이 된 인덱스를 반환한다. 각각의 입력은 단 하나의 방법이 있다고 가정하며, 같은 배열의 요소를 두 번 사용하지 않도록 한다. 순서 상관없..
