Zero to Hero
article thumbnail
1079. Letter Tile Possibilities
Algorithm 2021. 8. 29. 12:36

Letter Tile Possibilities - 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 알파벳으로 구성된 문자열이 주어진다. 이 문자열의 문자들을 이용해 만들 수 있는 모든 문자열의 개수를 반환하는 문제다. 단 빈 문자열은 제외한다. Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA". 접근법 ..

article thumbnail
950. Reveal Cards In Increasing Order
Algorithm 2021. 8. 27. 18:25

Reveal Cards In Increasing Order - 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 정수 카드 목록 list가 주어진다. 이 list를 랜덤 하게 섞은 뒤, 아래 순서대로 카드를 뽑았을 때 카드를 뽑는 순서가 오름차순이 되게 하는 섞인 list를 반환하는 문제다. 뽑는 방법은 아래와 같다. 맨 앞의 카드를 뽑는다. 그다음 카드를 맨 뒤로 돌린다. 예시 Input: deck = [17,13,11,2,3,5,7] Output: [2,13,3..

article thumbnail
1557. Minimum Number of Vertices to Reach All Nodes
Algorithm 2021. 8. 25. 13:45

Minimum Number of Vertices to Reach All Nodes - 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 방향 그래프가 주어진다. 모든 그래프의 노드를 탐색할 수 있는 최소 개수의 노드 목록을 list로 반환하는 문제다. 답은 유일하다는 것이 보장되어있다. Input: n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]] Output: [0,3] Explanation: It's not possible to..

article thumbnail
1561. Maximum Number of Coins You Can Get
Algorithm 2021. 8. 24. 09:44

Maximum Number of Coins You Can Get - 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 3의 배 수개의 코인이 들어있는 list가 주어진다. 임의의 코인 3개씩을 집어서 자신은 2번째로 큰 코인만을 가져간다고 할 때, 획득할 수 있는 코인의 최대 합을 반환하는 문제다. 1. Greedy from typing import * from collections import deque class Solution: def maxCoins(self..

article thumbnail
1382. Balance a Binary Search Tree
Algorithm 2021. 8. 23. 13:12

Balance a Binary Search Tree - 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 이진 탐색 트리가 주어진다. 주어진 이진 탐색 트리를 균형 이진 탐색 트리로 만들어 반환하는 문제다. 균형 이진 탐색 트리는 모든 노드의 left, right subtree의 depth 차이가 1 이하인 이진 탐색 트리다. 1. 중위 순회를 이용한 트리 생성 class Solution: def balanceBST(self, root: TreeNode) -> Tr..

article thumbnail
1630. Arithmetic Subarrays
Algorithm 2021. 8. 22. 13:58

Arithmetic Subarrays - 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 Input: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5] Output: [true,false,true] Explanation: In the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence. In the ..