全站内容
medium
377. Combination Sum IV
#Problem Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fit in a 32-bit integer. …
105. Construct Binary Tree from Preorder and Inorder Traversal
#Problem Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. …
230. Kth Smallest Element in a BST
#Problem Given the root of a binary search tree, and an integer k, return the kᵗʰ smallest value (1-indexed) of all the values of the nodes in the tree. https://leetcode.com/problems/kth-smallest-element-in-a-bst/ Example 1: case1Input: …
102. Binary Tree Level Order Traversal
#Problem Given the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level). https://leetcode.com/problems/binary-tree-level-order-traversal/ Example 1: case1Input: root = …
1143. Longest Common Subsequence
#Problem Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some …
98. Validate Binary Search Tree
#Problem Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node …
347. Top K Frequent Elements
#Problem Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. https://leetcode.com/problems/top-k-frequent-elements/ Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: …
91. Decode Ways
#Problem You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> 'A' "2" -> 'B' ... "25" -> 'Y' "26" -> 'Z' However, while decoding the message, you realize that there …
213. House Robber II
#Problem You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. …
211. Design Add and Search Words Data Structure
#Problem Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) Adds word to the …