- Today
- Total
목록leetcode (186)
작심삼일
문제 링크: 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
문제 링크: https://leetcode.com/problems/trim-a-binary-search-tree/ 문제 Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be prove..
문제 링크: https://leetcode.com/problems/search-in-a-binary-search-tree/ 문제 You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null. 조건 The number of nodes in the tree is in the range [1, 5000]. 1