본문 바로가기

코딩테스트/LeetCode

(20)
[Python][LeetCode] letter Combinations of a phone number(전화번호 문자 조합) https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 문제 설명: 2에서 9까지 숫자가 주어졌을 때 전화번호로 조합 가능한 모든 문자를 출력하는 문제 이 문제는 전체를 탐색해서 푸는 조합 문제이다. dic = { "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz", "0": "+" } 자판기에 다음과 같이 있다고 했을때 '23' 을 입력받으면 'ad' , 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'cd', 'cf' 3*3 = 9개 출력을 하면 된다. 풀이 path = '' 를 정의하고 path..
[Python][LeetCode] Climbing Stairs(계단오르기) https://leetcode.com/problems/climbing-stairs/description/ Climbing Stairs - LeetCode Can you solve this real interview question? Climbing Stairs - You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Outpu leetcode.com 문제설명: 정상에 도달하기 위해 n 계단을 올라가야 한다. 정상에 도달하기 위한 ..
[Python][LeetCode] Intersection of Two Arrays(두 배열의 교집합) https://leetcode.com/problems/intersection-of-two-arrays/description/ Intersection of Two Arrays - LeetCode Can you solve this real interview question? Intersection of Two Arrays - Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Example 1: In leetcode.com 문제 설명: 두 배열이 주어졌을때 교집합을..
[Python][LeetCode] Search in Rotated Sorted Array(회전 정렬된 배열 검색) https://leetcode.com/problems/search-in-rotated-sorted-array/description/ Search in Rotated Sorted Array - LeetCode Can you solve this real interview question? Search in Rotated Sorted Array - There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 nums[right]: left = mid+1 el..
[Python][LeetCode] Binary Search(이진탐색) https://leetcode.com/problems/binary-search/description/ Binary Search - LeetCode Can you solve this real interview question? Binary Search - Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. leetcode.com 문제설명: 정렬된 리스트를 입력받아 이진검색으로 target에 해당하는 인덱스를 구..
[Python][LeetCode] Two Sum II (두 수의 합) https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/ Two Sum II - Input Array Is Sorted - LeetCode Can you solve this real interview question? Two Sum II - Input Array Is Sorted - Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two n leetcode.com 문제 설명:..
[Python][LeetCode] Search a 2D Matrix II(2D 매트릭스 검색) https://leetcode.com/problems/search-a-2d-matrix-ii/description/ Search a 2D Matrix II - LeetCode Can you solve this real interview question? Search a 2D Matrix II - Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: * Integers in each row are sorted in ascending fr leetcode.com 문제 설명: 행렬이 주어졌을때 target의 값을 구하..
[Python][leetCode] List Sort(리스트 정렬) https://leetcode.com/problems/sort-list/description/ Sort List - LeetCode Can you solve this real interview question? Sort List - Given the head of a linked list, return the list after sorting it in ascending order. Example 1: [https://assets.leetcode.com/uploads/2020/09/14/sort_list_1.jpg] Input: head = [4,2,1,3] Output: [1, leetcode.com 문제설명 연결 리스트가 주어졌을때 퀵 정렬로 정렬하는 방식으로 구현해보았다. quick sort 방식은..