- 博客(37)
- 收藏
- 关注
原创 [leetcode] Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2015-03-08 03:23:59 271
原创 [leetcode] Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st
2015-03-08 01:52:44 255
原创 [leetcode]Largest Number
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 ve
2015-03-07 05:15:46 258
原创 [leetcode] next permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible
2015-03-07 04:13:18 284
原创 [leetcode] Generate Parenthese
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:"((()))", "(()())", "(())()", "()(())", "()()
2015-03-06 08:54:18 362
原创 [leetcode] restore IP address
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
2015-03-06 05:12:56 302
转载 [leetcode] Repeated DNA sequence
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2015-03-05 14:39:38 262
原创 [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","
2015-03-05 08:27:37 264
原创 [leetcode] 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 timeEach intermediate word m
2015-03-05 01:04:48 303
原创 [leetcode] Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路: 先对左节点排序,然后遍历整个list, 如果当前右节点等于或者大于下一个interval的左
2015-03-04 12:07:44 232
原创 [leetcode] longest substring without repeating characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo
2015-03-01 04:10:15 237
原创 [leetcode] Jump Game I and II
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 i
2015-02-12 14:28:24 248
原创 [leetcode] Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2015-02-12 10:07:28 286
原创 [leetcode] 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). Fin
2015-02-11 06:22:13 478
转载 [leetcode]set matrix zero
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:我用了九章算法提供的算法,思路清晰简洁。1. 判断第一行和第一列是否有0,如果有,最后要把第一行和第一列全部清02. 遍历第二行第二列开始的剩下的元素,如果有0, 则对应该元素的第一行第一列的
2015-02-09 14:16:38 292
原创 [leetcode] Search a 2D matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2015-02-07 02:57:32 241
原创 [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
2015-01-22 03:46:30 261
原创 [leetcode] Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2014-12-27 04:30:58 231
原创 [leetcode] Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t
2014-12-24 15:08:50 283
原创 [Leetcode] Construct Binary Tree from Inorder and Postorder/Preorder and Inorder 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.思路:用递归的思想,inorder是先左,中,右,而postorder是左,右, 中。因而每次递归返回当前子
2014-12-24 11:21:33 341
转载 [leetcode] Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?思路
2014-11-25 05:08:15 224
原创 [leetcode] Rotate Image
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?思路:因为要in-place的进行
2014-11-24 14:09:22 214
原创 [leetcode] Spiral Matrix
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:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2014-11-24 00:07:25 217
原创 [leetcode] Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2014-11-23 04:39:54 215
原创 [leetcode] Unique Path II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2014-11-22 13:39:04 375
原创 [leetcode] Minimum Path Sum
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 at
2014-11-22 10:46:11 271
原创 [leetcode]Divide two integers
Divide two integers without using multiplication, division and mod operator.b
2014-11-21 10:11:48 238
转载 [leetcode] Reverse Linked List ii
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t
2014-11-18 06:19:22 211
原创 [leetcode] Insertion Sort List
Sort a linked list using insertion sort.思路:思路上和insertion sort
2014-11-18 04:31:54 243
原创 [leetcode]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,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->
2014-11-17 11:40:36 286
原创 [leetcode] Remove Duplicates from sorted array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,
2014-11-17 10:18:35 222
原创 [leetcode] Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2014-11-16 13:07:56 253
原创 [leetcode] Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va
2014-11-16 03:47:41 259
原创 [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.
2014-11-15 02:43:43 339
原创 [leetcode] Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:双指针法,如果有
2014-11-14 15:36:42 224
原创 [leetcode] 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 integers
2014-11-14 15:29:28 242
原创 [leetcode] 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 t
2014-11-14 09:05:41 266
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人