leetcode
文章平均质量分 83
huiliao
热爱机器学习数据挖掘,对C/C++、Python、Matlab、PHP等感兴趣,关注科技互联网发展,希望结识更多同道中人。
展开
-
leetcode-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, givens = "leetcode",dict = ["leet"原创 2013-11-24 20:20:39 · 1083 阅读 · 0 评论 -
leetcode-Reverse Words in a String
Reverse Words in a String Total Accepted: 15012 Total Submissions: 108513My SubmissionsGiven an input string, reverse the string word by word.For example,Given s = "the sky is blue",原创 2014-06-01 23:56:15 · 1056 阅读 · 0 评论 -
leetcode-WordLadder
Word Ladder Total Accepted: 10237 Total Submissions: 58140My SubmissionsGiven two words (start and end), and a dictionary, find the length of shortest transformation sequence from start原创 2014-05-24 18:11:17 · 1133 阅读 · 0 评论 -
leetcode-Word Search
Word Search Total Accepted: 11535 Total Submissions: 58659My SubmissionsGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of seq原创 2014-07-24 22:10:15 · 714 阅读 · 0 评论 -
leetcode-Unique Binary Search Trees II
Unique Binary Search Trees II Total Accepted: 10486 Total Submissions: 39239My SubmissionsGiven n, generate all structurally unique BST's (binary search trees) that store values 1...n.原创 2014-07-24 21:22:33 · 817 阅读 · 0 评论 -
leetcode-Word Ladder II
Word Ladder II Total Accepted: 6164 Total Submissions: 58601My SubmissionsGiven two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to en原创 2014-05-31 23:40:15 · 1101 阅读 · 0 评论 -
leetcode-Gas Station
Gas Station Total Accepted: 12195 Total Submissions: 50108My SubmissionsThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car w原创 2014-06-02 23:01:42 · 1073 阅读 · 0 评论 -
leetcode-Subsets
Subsets Total Accepted: 13267 Total Submissions: 48509My SubmissionsGiven a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-desc原创 2014-06-02 09:52:39 · 1215 阅读 · 0 评论 -
leetcode-Palindrome Partitioning II
Palindrome Partitioning II Total Accepted: 11791 Total Submissions: 66110My SubmissionsGiven a string s, partition s such that every substring of the partition is a palindrome.Return t原创 2014-07-27 18:09:12 · 1084 阅读 · 0 评论 -
Restore IP Addresses
Restore IP Addresses Total Accepted: 12696 Total Submissions: 61955My SubmissionsGiven a string containing only digits, restore it by returning all possible valid IP address combinations原创 2014-08-22 19:57:01 · 685 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Remove Duplicates from Sorted List II Total Accepted: 17137 Total Submissions: 69046My SubmissionsGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only d原创 2014-08-23 13:55:20 · 980 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array Total Accepted: 22879 Total Submissions: 70824My SubmissionsGiven a sorted array, remove the duplicates in place such that each element appear only on原创 2014-08-23 14:51:52 · 821 阅读 · 0 评论 -
Triangle
Triangle Total Accepted: 16109 Total Submissions: 60327My SubmissionsGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row原创 2014-08-23 15:53:07 · 1006 阅读 · 0 评论 -
Candy
Candy Total Accepted: 16107 Total Submissions: 85614My SubmissionsThere are N children standing in a line. Each child is assigned a rating value.You are giving candies to these c原创 2014-08-24 16:04:20 · 1038 阅读 · 0 评论 -
N-Queens
N-Queens Total Accepted: 12866 Total Submissions: 49759My SubmissionsThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each oth原创 2014-08-24 21:32:50 · 866 阅读 · 0 评论 -
Search in Rotated Sorted Array
Search in Rotated Sorted Array Total Accepted: 22300 Total Submissions: 77945My SubmissionsSuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6原创 2014-08-25 20:08:58 · 678 阅读 · 0 评论 -
leetcode-Sort List
Sort a linked list in O(n log n) time using constant space complexity. http://oj.leetcode.com/problems/sort-list/ O (n log n)的排序算法有快速排序、归并排序等,于是一开始用快速排序算法: /** * Definition for singly-lin原创 2013-11-18 10:43:11 · 1397 阅读 · 0 评论 -
leetcode-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.这道题跟之前的从中序和后序序列中构造二叉树类似的,换成了从先序和中序序列来构造。/** * Defi原创 2013-12-06 12:46:17 · 1153 阅读 · 0 评论 -
leetcode-Recover Binary Search Tree
题目说一个二叉搜索树的两个节点被错误交换,要求不改变树的结构恢复正常的二叉搜索树。原创 2014-01-03 21:42:10 · 1097 阅读 · 0 评论 -
leetcode-Insertion Sort List
Sort a linked list using insertion sort.对链表进行插入排序。方法一:按照传统插入排序方法,从第二个节点从最后一个节点,依次把节点插入到前面已排好序的链表中的正确位置。/** * Definition for singly-linked list. * struct ListNode { * int val; * Lis原创 2013-11-18 18:54:43 · 1065 阅读 · 0 评论 -
leetcode-Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.这道题如果用递归来求解是不难的,只要根据二叉树中序和后续遍历的特点即可,不知道非递归该如何求解?/*原创 2013-12-04 20:13:24 · 903 阅读 · 0 评论 -
leetcode-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原创 2013-12-04 19:13:43 · 929 阅读 · 0 评论 -
leetcode-Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2013-12-02 20:27:46 · 977 阅读 · 0 评论 -
leetcode-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", "+",原创 2013-11-30 11:58:11 · 804 阅读 · 0 评论 -
leetcode-Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2013-11-28 20:25:46 · 737 阅读 · 0 评论 -
leetcode-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原创 2013-11-28 20:06:09 · 947 阅读 · 0 评论 -
leetcode-Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.只要把数组中点的元素左边和右边的元素分开,把中点当做子树根节点,左边的元素是根节点左子树的节点,右边的元素是右子树的节点,递归操作即可。/** * Definition for binary tr原创 2013-11-28 19:38:53 · 772 阅读 · 0 评论 -
leetcode-Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.题目要找出根节点到叶子节点的最短距离。递归分治如下:/**原创 2013-11-28 19:20:03 · 802 阅读 · 0 评论 -
leetcode-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 f原创 2013-11-26 19:25:30 · 1110 阅读 · 0 评论 -
leetcode-Copy List with Random Pointer
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.链表数据结构如下所示:/** * Definit原创 2013-12-12 12:15:20 · 851 阅读 · 0 评论 -
leetcode-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-linke原创 2013-12-17 19:27:03 · 938 阅读 · 0 评论 -
leetcode-Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2013-12-17 17:37:49 · 895 阅读 · 0 评论 -
leetcode-Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2013-11-27 14:02:06 · 769 阅读 · 0 评论 -
leetcode-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","原创 2013-11-28 14:13:18 · 1280 阅读 · 0 评论 -
Sum Root to Leaf Numbers
Sum Root to Leaf Numbers Total Accepted: 26533 Total Submissions: 89186My SubmissionsQuestion Solution Given a binary tree containing digits from 0-9 only, each root-to-leaf pa原创 2014-11-09 22:51:29 · 1038 阅读 · 0 评论