LeetCode[45] Jump Game II

2016-11-01
阅读 1 分钟
1.8k
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. For example:Given array A = [2,3,1,1,4] The m...

LeetCode[285] Inorder Successor in BST

2016-11-01
阅读 1 分钟
3.9k
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Note: If the given node has no in-order successor in the tree, return null.

LeetCode[270] Closest Binary Search Tree Value

2016-11-01
阅读 1 分钟
2k
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note:Given target value is a floating point.You are guaranteed to have only one unique value in the BST that is closest to the target.

LeetCode[333] Largest BST Subtree

2016-11-01
阅读 2 分钟
3.8k
Given a binary tree, find the largest subtree which is a Binary SearchTree (BST), where largest means subtree with largest number of nodesin it. Note: A subtree must include all of its descendants. Here's anexample: {代码...} The Largest BST Subtree in this case is the highlighted one. The return...

LeetCode[337] House Robber III

2016-11-01
阅读 2 分钟
2.5k
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatic...

LeetCode[191] Number of 1 Bits

2016-11-01
阅读 1 分钟
1.8k
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.

LeetCode[72] Edit Distance

2016-10-31
阅读 2 分钟
1.6k
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a characterb) Delete a characterc) Replace a character

系统设计basic

2016-10-31
阅读 1 分钟
1.9k
系统设计Basic 常用数据存储

Graph: Topological Sort

2016-10-31
阅读 1 分钟
1.4k
Graph: Topological Sort 利用和detect cycle类似的思路, 用dfs + recursion解决。并且一定时一个有向图。 {代码...}

Graph: Detect cycle

2016-10-31
阅读 2 分钟
1.8k
Graph: Detect Cycle Detect if any cycle exists in the graph. 无向图 0 - 1 | / 2 对于无向图,需要记录一个previous node来判断这是不是无向图两个node之间的连接。 DFS {代码...} BFS同一层的节点会出现相连的情况。 {代码...} 有向图 不需要记录previous node; {代码...}

LeetCode[169] Majority Element

2016-10-31
阅读 1 分钟
1.7k
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array.

LeetCode[354] Russian Doll Envelopes

2016-10-31
阅读 3 分钟
3.5k
You have a number of envelopes with widths and heights given as a pairof integers (w, h). One envelope can fit into another if and only ifboth the width and height of one envelope is greater than the widthand height of the other envelope. What is the maximum number of envelopes can you Russian do...

LeetCode[329] Longest Increasing Path in a Matrix

2016-10-30
阅读 2 分钟
2.3k
Given an integer matrix, find the length of the longest increasingpath. From each cell, you can either move to four directions: left, right,up or down. You may NOT move diagonally or move outside of theboundary (i.e. wrap-around is not allowed). Example 1: nums = [ {代码...} Return 4 The longesti...

LeetCode[296] Best Meeting Point

2016-10-30
阅读 2 分钟
2.5k
A group of two or more people wants to meet and minimize the totaltravel distance. You are given a 2D grid of values 0 or 1, where each1 marks the home of someone in the group. The distance is calculatedusing Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| +|p2.y - p1.y|. For example, ...

LeetCode[300] Longest Increasing Subsequence

2016-10-30
阅读 2 分钟
2.4k
Given an unsorted array of integers, find the length of longestincreasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longestincreasing subsequence is [2, 3, 7, 101], therefore the length is 4.Note that there may be more than one LIS combination, it is onlynecessary for you ...

LeetCode[233] Number of Digit One

2016-10-30
阅读 1 分钟
3k
Given an integer n, count the total number of digit 1 appearing in allnon-negative integers less than or equal to n. For example: Given n = 13, Return 6, because digit 1 occurred in thefollowing numbers: 1, 10, 11, 12, 13.

LeetCode[397] Integer Replacement

2016-10-29
阅读 1 分钟
3.5k
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n witheither n + 1 or n - 1. What is the minimum number of replacementsneeded for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1

Leetcode[368] Largest Divisible Subset

2016-10-28
阅读 2 分钟
2k
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si% Sj = 0 or Sj % Si = 0. If there are multiple solutions, return any subset is fine. Example 1: nums: [1,2,3] Result: [1,2] (of course, [1,3] will also be ok) E...

LeetCode[312] Burst Balloons

2016-10-27
阅读 3 分钟
3.2k
思路DP的思想是bottom up, 每次的想法是设置一个window size = k, 并且这是left和right的window范围。在某一个window之下,考虑这个window内的能够组成的最大值,不断的扩大这个window size进行搜索。

LeetCode[321] Create Maximum Number

2016-10-27
阅读 3 分钟
2.1k
Given two arrays of length m and n with digits 0-9 representing two Create the maximum number of length k <= m + n from digits of The relative order of the digits from the same array must be Return an array of the k digits. You should try to optimize time and space complexity. Example 1: nums1...

Leetcode[421] Maximum XOR of Two Numbers in an Array

2016-10-26
阅读 2 分钟
6.4k
思路利用XOR的性质,a^b = c, 则有 a^c = b,且 b^c = a;所以每次从高位开始,到某一位为止,所能获得的最大的数。设置变量mask用来表示能形成的值,每一次将mask和其他的num相与得到的值加入set,表示在当前这一位上,数组里有这么多prefix。

[Leetcode]36 Valid Sudoku

2016-10-17
阅读 2 分钟
1.9k
Determine if a Sudoku is valid, according to: Sudoku Puzzles - TheRules. The Sudoku board could be partially filled, where empty cells arefilled with the character '.'. Note: A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.