[Leetcode] Simplify Path 化简路径

2015-10-03
阅读 2 分钟
4.2k
Given an absolute path for a file (Unix-style), simplify it. For example, {代码...}

[Leetcode] Course Schedule 课程计划

2015-10-02
阅读 5 分钟
7k
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, is it possible for yo...

[Leetcode] Largest Number 最大整数

2015-10-02
阅读 2 分钟
7.4k
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a stringinstead of an integer.

[Leetcode] Decode Ways 解码方式

2015-10-02
阅读 2 分钟
11.9k
A message containing letters from A-Z is being encoded to numbers using the following mapping: {代码...} Given an encoded message containing digits, determine the total number of ways to decode it. For example, Given encoded message "12", it could be decoded as "AB"(1 2) or "L" (12). The number o...

[Leetcode] Valid Anagram 验证变形词

2015-10-01
阅读 2 分钟
6k
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume the string contains only lowercase alphabets.

[Leetcode] Longest Consecutive Sequence 最长连续数列

2015-10-01
阅读 2 分钟
5.9k
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. Your algorithm should run in O(n) complexity.

[Leetcode] Unique Binary Search Trees 唯一二叉搜索树

2015-10-01
阅读 2 分钟
7.4k
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. {代码...}

[Leetcode] Search in Rotated Sorted Array 搜索旋转有序数组

2015-10-01
阅读 4 分钟
6.9k
Suppose a sorted array 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 the array return its index, otherwise return -1. You may assume no duplicate exists in the array.

[Leetcode] House Robber 打家劫舍

2015-09-30
阅读 2 分钟
10.5k
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 houses have security system connected and it will automatically contact the police if two adjacent hou...

[Leetcode] Implement Stack using Queues 用队列实现栈

2015-09-30
阅读 2 分钟
4.4k
和Implement Queue using Stack类似,我们也可以用两个队列来模拟栈的操作。当push时,我们将数字offer进非空的队列就行了。当pop时,因为要拿的是队列最后一个数,我们先将它前面的数offer进另一个队列,然后单独拿出最后一个数,并且不再offer进另一个队列,这样,另一个队列就少了最后一个数,而我们也拿到了最后一个...

[Leetcode] Compare Version Numbers 比较版本号

2015-09-29
阅读 2 分钟
7.2k
Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not represent a decimal point and...

[Leetcode] Remove Nth Node From End of List 移除倒数第N的节点

2015-09-29
阅读 2 分钟
3.1k
Given a linked list, remove the nth node from the end of list andreturn its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked listbecomes 1->2->3->5. Note: Given n will always be valid. Try to do thisin one ...

[Leetcode] Factorial Trailing Zeroes 末尾零

2015-09-29
阅读 1 分钟
6.1k
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity.

[Leetcode] Pascal's Triangle 杨辉三角形

2015-09-29
阅读 3 分钟
3.9k
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return {代码...}

[Leetcode] Remove Element 删除数组元素

2015-09-28
阅读 2 分钟
5k
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.

[Leetcode] Shortest Palindrome 最短回文拼接法

2015-09-27
阅读 3 分钟
5.8k
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "aaacecaaa". Given "abcd", return "dcbabcd".

[Leetcode] Closest Binary Search Tree Value 最近二叉搜索树值

2015-09-27
阅读 3 分钟
12.4k
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] Expression Add Operators 添加运算符

2015-09-27
阅读 3 分钟
16k
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value. Examples: {代码...}

[Leetcode] Basic Calculator 基本计算器

2015-09-26
阅读 5 分钟
10k
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces . You may assume that the given expression is always valid. Some examples: {代码...} Note: Do...

[Leetcode] Alien Dictionary 外文字典

2015-09-26
阅读 10 分钟
15.7k
There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language. For example,...

[Leetcode] Peeking Iterator 瞥一眼迭代器

2015-09-26
阅读 2 分钟
6.3k
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be returned by the next call to next(). Here is an example. Assume that the iterator is initialized to t...

[Leetcode] H-Index H指数

2015-09-26
阅读 3 分钟
11k
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h p...

[Leetcode] 3Sum Smaller 三数较小和

2015-09-26
阅读 2 分钟
10.6k
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target. For example, given nums = [-2, 0, 1, 3], and target = 2. Return 2. Because there are two triplets which...

[Leetcode] Binary Search Tree Iterator 二叉搜素树迭代器

2015-09-26
阅读 2 分钟
5.2k
Implement 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 hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tree.

[Leetcode] Fraction to Recurring Decimal 分数转为循环小数

2015-09-26
阅读 2 分钟
8.4k
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses. For example, Given numerator = 1, denominator = 2, return "0.5". Given numerator = 2, denominator = 1, ...

[Leetcode] Read N Characters Given Read4 用Read4 API读取N个字符

2015-09-26
阅读 3 分钟
15.8k
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file. By using the read4 API, implement the function int read(char *buf, int n) that reads n charac...

[Leetcode] Plus One 加一

2015-09-25
阅读 1 分钟
3.8k
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.

[Leetcode] Inorder Successor in BST 二叉搜索树中序下一个

2015-09-25
阅读 2 分钟
8.6k
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] Encode and Decode Strings 字符串编解码

2015-09-25
阅读 2 分钟
11.1k
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings. Machine 1 (sender) has the function:string encode(vector<string> strs) { // ... your code return encoded_string; } Machine 2 (re...

[Leetcode] Flatten 2D Vector 整平二维向量

2015-09-25
阅读 2 分钟
8.8k
Implement an iterator to flatten a 2d vector. For example, Given 2d vector = {代码...} By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,2,3,4,5,6].