Question: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s ...
Question: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s ...
Question: Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Solution 1: Priority Queue public class Element{ ...
做法1: class Solution { private: vector<vector<int>> res; vector<int> group; public: void dfs(vector<int>& v){ if(v.size()==0){//计入结果的条件 re...
2 Sum 3 Sum and 4 Sum questions are similar, and the key of solving the problem is using 2 pointer. 2 Sum: Question: Given an array of integers that is already sorted in ascending order, find two numb...
Question: An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is ....
Question: Write a program to find the node at which the intersection of two singly linked lists begins. Solution1: Two Pointers public class Solution { public ListNode getIntersectionNode(ListNode...
LeetCode link: https://leetcode.com/problems/copy-list-with-random-pointer/ Question Description: A linked list is given such that each node contains an additional random pointer which could point to...
Question: Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). ...
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. ...
Question: Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list – whose elements may also be integers or other lists. ...
Question: mplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. ...
Question Given an array numsof n integers where n > 1, return an array output such that output[i]is equal to the product of all the elements of numsexcept nums[i]. Example: Input: [1,2,3,4] ...
题目: Given a 2D board containing'X'and'O'(the letter O), capture all regions surrounded by'X'. A region is captured by flipping all'O's into'X's in that surrounded region. Example: ...
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this...
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. ...
Question: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Solution1: ...
The n-queens puzzle is the problem of placing n queens on an n�n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. ...
Question: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this ...
Subsets Total Accepted:13267Total Submissions:48509My Submissions Given a set of distinct integers,S, return all possible subsets. Note: ...Elements in a subset mu...
Question: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Example: Input: “23” Output: [“ad”, “ae”, “af”, “bd”,...
Question: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] ...
����������������������������������������������������������������������������������������������������...
2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit....
����������������������������������������������������������������������������������������������������...
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C ...
Question: Given a string of comma separated values, verify whether it is a correct preorder traversal serialization of a binary tree. Find an algorithm without reconstructing the tree. ...