![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
文章平均质量分 75
dongbeier
这个作者很懒,什么都没留下…
展开
-
515 Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]这道题让我们找二叉树每行的最大的结点值,那么实际上最直...原创 2018-05-13 07:24:36 · 84 阅读 · 0 评论 -
127 Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a time...原创 2018-05-13 07:28:49 · 77 阅读 · 0 评论 -
238 Product of Array Except Self
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Output: [24,1...原创 2018-05-13 07:29:01 · 76 阅读 · 0 评论 -
104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children.Ex...原创 2018-05-13 07:29:12 · 79 阅读 · 0 评论 -
76 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:If there i...原创 2018-05-13 07:29:22 · 213 阅读 · 1 评论 -
46 Permutations
Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]函数 next_permutation()/**...原创 2018-05-13 07:29:36 · 317 阅读 · 0 评论 -
33 Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in t...原创 2018-05-13 07:29:45 · 68 阅读 · 0 评论 -
744 Find Smallest Letter Greater Than Target
Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.Letters also w...原创 2018-05-13 07:30:04 · 101 阅读 · 0 评论 -
311 Sparse Matrix Multiplication
Given two sparse matrices A and B, return the result of AB.You may assume that A's column number is equal to B's row number.Example:A = [ [ 1, 0, 0], [-1, 0, 3]]B = [ [ 7, 0, 0 ], [ 0, 0, 0...原创 2018-05-13 07:30:11 · 122 阅读 · 0 评论 -
150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two integers should...原创 2018-05-13 07:30:16 · 122 阅读 · 0 评论 -
464 Can I Win
In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.What if we change the game so th...原创 2018-05-13 07:30:23 · 143 阅读 · 0 评论 -
57 Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1...原创 2018-05-13 07:28:37 · 71 阅读 · 0 评论 -
101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the...原创 2018-05-13 07:28:27 · 81 阅读 · 0 评论 -
647 Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of...原创 2018-05-13 07:28:17 · 93 阅读 · 0 评论 -
367 Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Returns: TrueEx...原创 2018-05-13 07:24:45 · 107 阅读 · 0 评论 -
730 Count Different Palindromic Subsequences
Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7.A subsequence of a string S is obtained by deleting 0 or more characters ...原创 2018-05-13 07:24:54 · 176 阅读 · 0 评论 -
633 Sum of Square Numbers
Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2= c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5Example 2:Input: 3Outp...原创 2018-05-13 07:25:03 · 141 阅读 · 0 评论 -
671 Second Minimum Node In a Binary Tree
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's va...原创 2018-05-13 07:26:39 · 122 阅读 · 0 评论 -
47 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]重新实现next_permutation()/** * * ...原创 2018-05-13 07:26:57 · 85 阅读 · 0 评论 -
173 Binary Search Tree Iterator
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.Note: next() and hasN...原创 2018-05-13 07:27:08 · 96 阅读 · 0 评论 -
21 Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1...原创 2018-05-13 07:27:28 · 61 阅读 · 0 评论 -
23 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4->4...原创 2018-05-13 07:27:39 · 57 阅读 · 0 评论 -
198 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2018-05-13 07:27:50 · 77 阅读 · 0 评论 -
103 Binary Tree Zigzag Level Order Traversal
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).For example:Given binary tree [...原创 2018-05-13 07:28:00 · 66 阅读 · 0 评论 -
1 Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...原创 2018-05-13 07:30:29 · 60 阅读 · 0 评论 -
34 Search for a Range
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the tar...原创 2018-05-13 07:30:38 · 82 阅读 · 0 评论 -
236 Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v an...原创 2018-05-13 07:30:45 · 104 阅读 · 0 评论 -
698 Partition to K Equal Sum Subsets
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into knon-empty subsets whose sums are all equal.Example 1:Input: nums = [4, 3, 2, 3, 5, 2, 1]...原创 2018-05-11 03:08:47 · 89 阅读 · 0 评论 -
245 Shortest Word Distance III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 and word2, return the shortest distance between the...原创 2018-05-11 02:46:12 · 134 阅读 · 0 评论 -
254 Factor Combinations
Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors.Note: Each combina...原创 2018-05-11 02:40:53 · 206 阅读 · 0 评论 -
366 Find Leaves of Binary Tree
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps until the tree is empty.Example:Given binary tree 1 / \ 2 3 / \ ...原创 2018-05-11 02:34:51 · 155 阅读 · 0 评论 -
716 Max Stack
Design a max stack that supports push, pop, top, peekMax and popMax. push(x) -- Push element x onto stack.pop() -- Remove the element on top of the stack and return it.top() -- Get the element on the ...原创 2018-05-11 02:25:32 · 417 阅读 · 0 评论 -
156 Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin...原创 2018-05-11 02:05:46 · 203 阅读 · 0 评论 -
256 Paint House
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the ho...原创 2018-05-11 01:54:01 · 104 阅读 · 0 评论 -
170 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations:add and find.add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which su...原创 2018-05-11 01:41:05 · 130 阅读 · 0 评论 -
364 Nested List Weight Sum II
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.Each element is either an integer, or a list -- whose elements may also be integers or other lists.D...原创 2018-05-11 01:33:16 · 137 阅读 · 0 评论 -
244 Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you ...原创 2018-05-11 01:26:52 · 92 阅读 · 0 评论 -
205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another char...原创 2018-05-13 07:32:41 · 90 阅读 · 0 评论 -
53 Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation: [...原创 2018-05-13 07:32:34 · 105 阅读 · 0 评论 -
297 Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be...原创 2018-05-13 07:32:28 · 233 阅读 · 0 评论