leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 思路还是比较简单的,在中
阅读全文
posted @
2018-03-26 22:04
Beserious
阅读(108)
推荐(0)
leetcode 309. Best Time to Buy and Sell Stock with Cooldown
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple
阅读全文
posted @
2018-03-23 23:55
Beserious
阅读(151)
推荐(0)
leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee
摘要:Your are given an array of integers prices, for which the i th element is the price of a given stock on day i; and a non negative integer fee represen
阅读全文
posted @
2018-03-23 23:47
Beserious
阅读(255)
推荐(0)
leetcode 32. Longest Valid Parentheses
摘要:Given a string containing just the characters and , find the length of the longest valid (well formed) parentheses substring. For , the longest valid
阅读全文
posted @
2018-03-21 21:24
Beserious
阅读(119)
推荐(0)
leetcode 224. Basic Calculator
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or
阅读全文
posted @
2018-03-21 21:06
Beserious
阅读(120)
推荐(0)
leetcode 540. Single Element in a Sorted Array
摘要:Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element
阅读全文
posted @
2018-03-21 20:16
Beserious
阅读(134)
推荐(0)
leetcode 109. Convert Sorted List to Binary Search Tree
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height balanced bina
阅读全文
posted @
2018-03-17 10:27
Beserious
阅读(129)
推荐(0)
leetcode 3. Longest Substring Without Repeating Characters
摘要:Given a string, find the length of the longest substring without repeating characters. 思路:用map维护区间内各个字母的数量,然后遇到已经访问过的就进行滑动区间,来得到符合条件的区间,然后求最大区间长度。 虽然时
阅读全文
posted @
2018-03-17 10:21
Beserious
阅读(130)
推荐(0)
leetcode 84. Largest Rectangle in Histogram
摘要:Given n non negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist
阅读全文
posted @
2018-03-13 22:36
Beserious
阅读(149)
推荐(0)
leetcode 338. Counting Bits
摘要:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and r
阅读全文
posted @
2018-03-12 20:36
Beserious
阅读(177)
推荐(0)
leetcode 797. All Paths From Source to Target
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N 1, and return them in any order. The graph is given as follo
阅读全文
posted @
2018-03-11 20:36
Beserious
阅读(384)
推荐(0)
leetcode 796. Rotate String
摘要:We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example,
阅读全文
posted @
2018-03-11 20:20
Beserious
阅读(290)
推荐(0)
leetcode 153. Find Minimum 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). Find
阅读全文
posted @
2018-03-10 21:32
Beserious
阅读(146)
推荐(0)
leeetcode 735. Asteroid Collision
摘要:We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign r
阅读全文
posted @
2018-03-09 20:13
Beserious
阅读(180)
推荐(0)
leetcode 795. Number of Subarrays with Bounded Maximum
摘要:We are given an array A of positive integers, and two positive integers L and R (L R`的数字,那么此时就重新开始计数。思路很简单,但是实现起来..... 代码中b维护的是`& A, int L, int R) { i
阅读全文
posted @
2018-03-08 18:57
Beserious
阅读(328)
推荐(0)
leetcode 792. Number of Matching Subsequences
摘要:Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of S. 思路:先用vector记录每个字母出现的位置,然后遍历每个单词,如果每个字母的位置是递增的那
阅读全文
posted @
2018-03-06 21:58
Beserious
阅读(350)
推荐(0)
leetcode 4. Median of Two Sorted Arrays
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh
阅读全文
posted @
2018-03-01 21:30
Beserious
阅读(132)
推荐(0)
leetcode 334. Increasing Triplet Subsequence
摘要:Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should:
阅读全文
posted @
2018-03-01 11:20
Beserious
阅读(96)
推荐(0)
leetcode 235. Lowest Common Ancestor of a Binary Search Tree
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. 还是bst树,bst树的左节点小于根节点小于右节点,依据此性质递归比较既可以找到公共父节点。注
阅读全文
posted @
2018-03-01 10:36
Beserious
阅读(86)
推荐(0)
leetcode 459. Repeated Substring Pattern
摘要:Given a non empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may a
阅读全文
posted @
2018-03-01 10:32
Beserious
阅读(103)
推荐(0)
leetcode 501. Find Mode in Binary Search Tree
摘要:Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is define
阅读全文
posted @
2018-03-01 09:41
Beserious
阅读(110)
推荐(0)
leetcode 530. Minimum Absolute Difference in BST
摘要:Given a binary search tree with non negative values, find the minimum absolute difference between values of any two nodes. 题目大意,求bst树任意两点的最小绝对距离。 思路,中
阅读全文
posted @
2018-03-01 09:34
Beserious
阅读(113)
推荐(0)
leetcode 543. Diameter of Binary Tree
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwe
阅读全文
posted @
2018-03-01 09:28
Beserious
阅读(102)
推荐(0)
leetcode 551. Student Attendance Record I
摘要:You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent. 'L' : L
阅读全文
posted @
2018-03-01 09:14
Beserious
阅读(121)
推荐(0)
leetcode 563. Binary Tree Tilt
摘要:Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt
阅读全文
posted @
2018-03-01 09:12
Beserious
阅读(106)
推荐(0)
leetcode 598. Range Addition II
摘要:Given an m n matrix M initialized with all 0's and several update operations. Operations are represented by a 2D array, and each operation is represen
阅读全文
posted @
2018-03-01 09:09
Beserious
阅读(106)
推荐(0)
leetcode 599. Minimum Index Sum of Two Lists
摘要:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to h
阅读全文
posted @
2018-03-01 09:05
Beserious
阅读(106)
推荐(0)
leetcode 606. Construct String from Binary Tree
摘要:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be rep
阅读全文
posted @
2018-03-01 08:59
Beserious
阅读(107)
推荐(0)
leetcode 690. Employee Importance
摘要:You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id.
阅读全文
posted @
2018-03-01 08:53
Beserious
阅读(117)
推荐(0)