Leetcode[35] Search Insert Position

2018-01-29
阅读 1 分钟
2.3k
Given a sorted array and a target value, return the index if thetarget is found. If not, return the index where it would be if it wereinserted in order.You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input: [1,3,5,6], 2 Output: 1 Example 3: Input: [1...

Leetcode[4] Median of two sorted arrays

2018-01-29
阅读 3 分钟
2.3k
There are two sorted arrays nums1 and nums2 of size m and nrespectively.Find the median of the two sorted arrays. The overall run timecomplexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 = 2.5

LC 技巧点

2016-12-28
阅读 1 分钟
1.2k
综合总结 MAXHeap的生成 {代码...}

Comparator改写

2016-12-27
阅读 1 分钟
2.9k
Comparator改写 MinQueue 的改写 {代码...} 或者是 {代码...} MaxQueue的改写 {代码...} 或者是 {代码...}

Leetcode[224] Basic Calculator

2016-12-06
阅读 3 分钟
2.3k
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ),the plus +, minus sign - or * or /, non-negative integers and empty spaces . You may assume that the given expression is always valid. Some examples: {代码...}

Leetcode[227] Basic Calculator II

2016-12-06
阅读 2 分钟
2.2k
Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, /operators and empty spaces . The integer division should truncatetoward zero. You may assume that the given expression is always valid. Some examples: {代码...}

Leetcode[152] Maximum Product Subarray

2016-11-28
阅读 1 分钟
2.2k
Find the contiguous subarray within an array (containing at least onenumber) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3]has the largest product = 6.

Leetcode[313] Super Ugly Number

2016-11-24
阅读 1 分钟
2.5k
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are inthe given prime list primes of size k. For example, [1, 2, 4, 7, 8,13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super uglynumbers given primes = [2, 7, 13, 19] o...

LeetCode[124] Binary Tree Maximum Path Sum

2016-11-23
阅读 1 分钟
3k
Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from somestarting node to any node in the tree along the parent-child The path must contain at least one node and does not need go through the root. For example: Given the below binary tre...

Leetcode[76] Minimum Window Substring

2016-11-19
阅读 2 分钟
2k
Given a string S and a string T, find the minimum window in S whichwill contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC".

Leetcode[413] Arithmetic Slices

2016-11-17
阅读 2 分钟
3k
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence:

LeetCode[132] Pattern

2016-11-17
阅读 2 分钟
3.5k
Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list. Note: n will be less than 15,000.

Leetcode[315] Count of Smaller Numbers After Self

2016-11-14
阅读 3 分钟
3.5k
ou are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

LeetCode[117] Population Next Right Pointers in Each Node II

2016-11-09
阅读 1 分钟
3k
LeetCode[117] Population Next Right Pointers in Each Node II {代码...} Iteration 复杂度O(N),O(1) 思路设置一个dummy node 指向下一层要遍历的节点的开头的位置。 代码 {代码...}

LeetCode[48] Rotate Image

2016-11-09
阅读 1 分钟
2.1k
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place?

LeetCode[54] Spiral Matrix

2016-11-09
阅读 2 分钟
2.1k
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following matrix:

LeetCode[138] Copy List with Random Pointer

2016-11-09
阅读 1 分钟
3k
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

LeetCode[218] The Skyline Problem

2016-11-09
阅读 3 分钟
2.6k
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline formed by these bui...

Leetcode[332] Reconstruct Itinerary

2016-11-09
阅读 2 分钟
5.1k
Given a list of airline tickets represented by pairs of departure andarrival airports [from, to], reconstruct the itinerary in order. Allof the tickets belong to a man who departs from JFK. Thus, theitinerary must begin with JFK. Note: If there are multiple valid itineraries, you should return th...

Leetcode[161] One Edit Distance

2016-11-09
阅读 1 分钟
2.6k
Given two strings S and T, determine if they are both one edit distance apart.

Leetcode[257] Binary Tree Paths

2016-11-09
阅读 2 分钟
3k
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree:

LintCode Coins in a line III

2016-11-07
阅读 2 分钟
3.9k
There are n coins in a line. Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins.Could you please decide the first player will win or lose? ExampleGiven array A = [3,2,2], return true.Given arra...

Lintcode Coins in a line II

2016-11-07
阅读 2 分钟
2.6k
有 n 个不同价值的硬币排成一条线。两个参赛者轮流从左边依次拿走 1 或 2 个硬币,直到没有硬币为止。计算两个人分别拿到的硬币总价值,价值高的人获胜。 请判定 第一个玩家 是输还是赢? 样例给定数组 A = [1,2,2], 返回 true.给定数组 A = [1,2,4], 返回 false.

Lintcode Coins in a line

2016-11-06
阅读 1 分钟
2.5k
有 n 个硬币排成一条线。两个参赛者轮流从右边依次拿走 1 或 2 个硬币,直到没有硬币为止。拿到最后一枚硬币的人获胜。 请判定 第一个玩家 是输还是赢? n = 1, 返回 true.n = 2, 返回 true.n = 3, 返回 false.n = 4, 返回 true.n = 5, 返回 true.

Leetcode[42] Trapping Rain Water

2016-11-06
阅读 2 分钟
2.2k
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.

LeetCode[385] Mini Parser

2016-11-06
阅读 2 分钟
4.1k
Given s = "[123,[456,[789]]]", Return a NestedInteger object containing a nested list with 2 elements: An integer containing value 123. A nested list containing two elements: An integer containing value 456. A nested list with one element: An integer containing value 789.

LeetCode[287] Find the Duplicate Number

2016-11-05
阅读 2 分钟
3k
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. Note:You must not modify the array (assume the array is read only).You must...

LeetCode[139] Word Break

2016-11-04
阅读 1 分钟
2.8k
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because "leetcode" can be segmented as "leet code".

LeetCode[316] Remove Duplicate Letters

2016-11-04
阅读 2 分钟
3.6k
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example:Given "bcabc"Return "abc" Given "cbacdcbc"Return "acdb"

LeetCode[22] Generate Parentheses

2016-11-01
阅读 1 分钟
2.2k
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: ["((()))", "(()())", "(())()", "()(())", "()()()"]