본문 바로가기

코딩테스트/LeetCode20

[Python][LeetCode] Insertion Sort List(삽입 정렬 리스트) https://leetcode.com/problems/insertion-sort-list/description/ 문제 설명: 연결리스트로 노드들이 주어졌을때 이것을 삽입정렬 방식으로 정렬하는 것이다. head는 링크들로 연결된 노드들로 이루어져있다. 1. 더미노드를 만든다. 2. 더미노드에 다음노드로 head가 가르키는 노드 값을 새로운 노드로 만들어 next로 추가한다. 3. 더미노드에 포인터 p를 두어 p가 증가하면서 새로운 노드들이 위치 할 곳을 찾는다. 예시 [4,6,5,9,1] test = ListNode(4, ListNode(6, ListNode(2, ListNode(9, ListNode(1))))) Solution().insertionSortList_2(test) 더미노드는 지금 빈 노드를 .. 2023. 10. 28.
[Python] [LeetCode] Balanced Binary Tree (균형 이진 트리) https://leetcode.com/problems/balanced-binary-tree/description/ Balanced Binary Tree - LeetCode Can you solve this real interview question? Balanced Binary Tree - Given a binary tree, determine if it is height-balanced. Example 1: [https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg] Input: root = [3,9,20,null,null,15,7] Output: true Exam leetcode.com 문제 설명: 이진트리가 주어지면 균형 잡힌 이진트리인지 확인하고.. 2023. 10. 26.
[Python][LeetCode] Invert Tree https://leetcode.com/problems/invert-binary-tree/description/ Invert Binary Tree - LeetCode Can you solve this real interview question? Invert Binary Tree - Given the root of a binary tree, invert the tree, and return its root. Example 1: [https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg] Input: root = [4,2,7,1,3,6,9] Output: [4 leetcode.com 문제 설명 주어진 리스트를 트리로 바꿔 왼쪽과 오른쪽이 바뀐 값을 출력.. 2023. 10. 25.
[LeetCode] Subsets(부분집합) https://leetcode.com/problems/subsets/description/ Subsets - LeetCode Can you solve this real interview question? Subsets - Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Example 1: Input: n leetcode.com 문제 설명 부분집합을 구하는 문제이다. [1,2,3] 리스트가 주어졌을때 총 [],[1],[2],[3],[1,.. 2023. 10. 23.