- Today
- Total
목록스터디 (246)
작심삼일
문제 링크: https://leetcode.com/problems/smallest-string-with-swaps/ 문제 You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at any pair of indices in the given pairs any number of times. Return the lexicographically smallest string that s can be changed to after using the swap..
문제 링크: https://leetcode.com/problems/min-cost-to-connect-all-points/ 문제 You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [$x_i, y_i$]. The cost of connecting two points [$x_i, y_i$] and [$x_j, y_j$] is the manhattan distance between them: |$x_i - x_j$| + |$y_i - y_j$|, where |val| denotes the absolute value of val. Return the minimum ..
문제 링크: https://leetcode.com/problems/peeking-iterator/ 문제 Design an iterator that supports the peek operation on an existing iterator in addition to the hasNext and the next operations. Implement the PeekingIterator class: PeekingIterator(Iterator nums) Initializes the object with the given integer iterator iterator. int next() Returns the next element in the array and moves the pointer to the n..
문제 링크: https://leetcode.com/problems/design-hashmap/ 문제 Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value. int get(int key) returns the value to which th..
문제 링크: https://leetcode.com/problems/design-hashset/ 문제 Design a HashSet without using any built-in hash table libraries. Implement MyHashSet class: void add(key) Inserts the value key into the HashSet. bool contains(key) Returns whether the value key exists in the HashSet or not. void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing. 조건 0 None: ..
문제 링크: https://leetcode.com/problems/binary-search-tree-iterator/ 문제 Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any el..
문제 링크: https://leetcode.com/problems/recover-binary-search-tree/ 문제 You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. 조건 The number of nodes in the tree is in the range [2, 1000]. $-2^{31}$ root.val: if not self.change1: self.change1 = self.prev self.change2 = root self..
문제 링크: https://leetcode.com/problems/kth-smallest-element-in-a-bst/ 문제 Given the root of a binary search tree, and an integer k, return the $k^{th}$ smallest value (1-indexed) of all the values of the nodes in the tree. 조건 The number of nodes in the tree is n. 1