
leetcode
njudongchen
这个作者很懒,什么都没留下…
展开
-
word-break-ii
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s =”catsan原创 2017-08-29 22:44:17 · 394 阅读 · 0 评论 -
anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case题目的意思是如果字符串容器中存在同构词(包含相同字母),则将同构词保存下来,需要的注意的是第一次出现的单词的处理.class Solution {public: v原创 2017-05-04 22:58:14 · 378 阅读 · 0 评论 -
最小路径和
题目描述Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right a原创 2017-04-26 14:33:00 · 358 阅读 · 0 评论 -
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). For example, S =”ADOBECODEBANC” T =”ABC” Minimum window is”BANC”. Note:原创 2017-05-04 21:22:52 · 437 阅读 · 0 评论 -
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原创 2017-04-22 14:53:51 · 341 阅读 · 0 评论 -
palindrome-partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s =”aab”, Return [ [“aa”,”b”],原创 2017-04-17 15:51:18 · 307 阅读 · 0 评论 -
palindrome-partitioning-ii
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s =”aab”, Return1since原创 2017-04-17 00:09:48 · 520 阅读 · 0 评论 -
symmetric-tree
题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3But the follo原创 2017-04-20 12:10:41 · 273 阅读 · 0 评论 -
two-sum
题目描述Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, wh原创 2017-04-19 21:10:36 · 264 阅读 · 0 评论 -
decode-ways
题目描述A message containing letters fromA-Zis being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total numbe原创 2017-04-19 19:47:03 · 437 阅读 · 0 评论 -
restore-ip-addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given”25525511135”, return[“255.255.11.135”, “255.255.111.35”]. (Order does no原创 2017-04-19 17:47:38 · 362 阅读 · 0 评论 -
construct-binary-tree-from-preorder-and-inorder
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree./** * Definition for binary tree * struct TreeNode { *原创 2017-05-24 22:05:02 · 386 阅读 · 0 评论 -
unique-binary-search-trees
题目描述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. 1 3 3 2 1 \原创 2017-04-24 22:07:50 · 437 阅读 · 0 评论 -
unique-binary-search-trees-ii
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1 3 3原创 2017-04-25 00:13:52 · 323 阅读 · 0 评论 -
股票交易
题目描述Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You ...原创 2017-09-05 21:40:29 · 561 阅读 · 0 评论 -
single-number-ii
题目描述Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2017-07-28 22:12:48 · 499 阅读 · 0 评论 -
n-queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle. Each sol原创 2017-05-22 11:46:28 · 415 阅读 · 0 评论 -
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./** * Definition for singly-linked list. * struct List原创 2017-05-22 10:23:53 · 449 阅读 · 0 评论 -
jump-game
题目描述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. Determine if原创 2017-04-27 10:33:21 · 395 阅读 · 0 评论 -
plus-one
Given a number represented as an array of digits, plus one to the number.easy~class Solution {public: vector<int> plusOne(vector<int> &digits) { int len=digits.size(); if(len<=0)原创 2017-04-26 22:30:28 · 460 阅读 · 0 评论 -
remove-duplicates-from-sorted-list
题目描述Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given1->1->2, return1->2. Given1->1->2->3->3, return1->2->3./** * Definition for singly-l原创 2017-04-26 22:05:14 · 354 阅读 · 0 评论 -
add-binary
Given two binary strings, return their sum (also a binary string). For example, a =”11” b =”1” Return”100”. 模拟即可class Solution {public: string addBinary(string a, string b) { string r原创 2017-04-26 16:41:12 · 361 阅读 · 0 评论 -
set-matrix-zeroes
题目描述 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(原创 2017-04-26 13:26:20 · 491 阅读 · 0 评论 -
sort-colors
题目描述 Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the intege原创 2017-04-25 15:44:19 · 448 阅读 · 0 评论 -
longest-consecutive-sequence
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].原创 2017-04-14 22:09:30 · 219 阅读 · 0 评论 -
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./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNo原创 2017-04-19 12:55:44 · 472 阅读 · 0 评论 -
container-with-most-water
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin原创 2017-04-19 11:03:49 · 300 阅读 · 0 评论 -
candy
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one can原创 2017-04-03 17:29:09 · 521 阅读 · 0 评论 -
unique-path
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bot原创 2017-04-03 15:17:17 · 385 阅读 · 0 评论 -
reverse-integer
题目描述 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before co原创 2017-04-03 14:56:36 · 257 阅读 · 0 评论 -
word-break
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, given s =”leetcode”, dict =[“leet”, “co原创 2017-04-02 22:05:46 · 239 阅读 · 0 评论 -
reorder-list
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes’ values. For example, Given{1,2,3,4}, reorder it to{1,4,2,原创 2017-03-22 15:43:26 · 281 阅读 · 0 评论 -
binary-tree-postorder-traversal
题目描述Given a binary tree, return the postorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1]. Note: Recursive solution is tri原创 2017-03-22 11:38:34 · 250 阅读 · 0 评论 -
insertion-sort-list
题目描述Sort a linked list using insertion sort.链表的插入排序,不难/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {原创 2017-03-22 11:18:39 · 273 阅读 · 0 评论 -
sort-list
题目描述Sort a linked list in O(n log n) time using constant space complexity.使用归并排序,严格来说空间复杂度并不是常量,因为用到了栈,但是好像大多数人都是利用归并排序的,姑且这么写吧。比较简单。/** * Definition for singly-linked list. * struct ListNode { *原创 2017-03-21 21:57:55 · 191 阅读 · 0 评论 -
max-point-on-a-line
题目描述Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.穷举法,遍历即可,注意判断斜率需要转成double型/** * Definition for a point. * struct Point { * int x; * in原创 2017-03-21 18:55:54 · 483 阅读 · 0 评论 -
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. Some examples: [“2”, “1”, “+”, “3”, ““]原创 2017-03-19 21:50:39 · 295 阅读 · 0 评论 -
surrounded-regions
Given a 2D board containing’X’and’O’, capture all regions surrounded by’X’. A region is captured by flipping all’O’s into’X’s in that surrounded region . For example, X X X X X O O X X X O X X O原创 2017-04-17 17:37:30 · 295 阅读 · 0 评论 -
word-ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a time Each intermediate word mu原创 2017-04-17 19:56:05 · 438 阅读 · 0 评论 -
remove-duplicates-from-sorted-list-ii
题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given1->2->3->3->4->4->5, return1->2->5. Given1->1->1原创 2017-04-28 11:11:56 · 307 阅读 · 0 评论