본문 바로가기

리트코드14

[코딩 테스트] 리트코드207 -Course Schedule (Medium) in Python There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, return fal.. 2021. 6. 2.
[코딩 테스트] 리트코드70 - Climbing Stairs (Easy) in Python 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? n 개의 계단을 올라야 목적지에 다다를 수 있다. 한 번에 1개, 혹은 2개 계단씩 오를 수 있다면, 얼마나 다양한 방법으로 목적지에 갈 수 있을까? 예시 Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Constraints 1 >>>>>> 파이썬 1초 평균 연산 1억 따라서 Me.. 2021. 6. 1.
[코딩 테스트] 리트코드 208 - Implement Trie(Prefix Tree) A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. Implement the Trie class: 트라이 구조를 문제에서 요구하는 대로 구현하세요. Trie() Initializes the trie object. void insert(String word) Inserts the string word into the trie. boolean sear.. 2021. 5. 31.
[코딩 테스트] 리트코드 19 - Remove Nth Node From End of List(Medium) in Python Given the head of a linked list, remove the nth node from the end of the list and return its head 연결 리스트의 head가 주어졌을 때, 연결 리스트의 끝에서 n번째 노드를 삭제하고 연결 리스트의 head를 리턴하세요! Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] 풀이 나는 문제에서 말하는 소위 "Two-Pass Solution"으로 풀었다. 처음에 한 포인터로 연결 리스트를 순회하면서 연결 리스트의 길이 (length) 를 알아내고, 두번째 포인터로 (length - n)노드의 .. 2021. 5. 29.