
leetcode
文章平均质量分 57
所有昵称都被用了呢
在看coursera的text retrieval and search engines. 发现好难坚持。。。。。回家就想睡觉。。。。。。1个月过去了。。。还在week3
展开
-
开始刷leetcode day18:Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin转载 2015-05-21 11:59:29 · 285 阅读 · 0 评论 -
开始刷leetcode day32: Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.Java:/** * Definition for原创 2015-06-05 12:27:10 · 352 阅读 · 0 评论 -
开始刷leetcode day20:Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Java:/** * Definiti原创 2015-05-23 10:20:23 · 318 阅读 · 0 评论 -
开始刷leetcode day20:Generate Parentheses
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-05-23 09:26:14 · 280 阅读 · 0 评论 -
开始刷leetcode day16: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.转载 2015-05-19 12:52:39 · 306 阅读 · 0 评论 -
开始刷leetcode day20:First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant转载 2015-05-23 09:58:52 · 308 阅读 · 0 评论 -
开始刷题leetcode day37: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-06-10 14:01:53 · 337 阅读 · 0 评论 -
开始刷题 leetcode day39: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转载 2015-06-12 13:01:02 · 294 阅读 · 0 评论 -
开始刷leetcode day62:Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2015-07-12 05:48:47 · 301 阅读 · 0 评论 -
开始刷leetcode day62: Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain du原创 2015-07-12 05:01:27 · 232 阅读 · 0 评论 -
开始刷leetcode day 16: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原创 2015-05-19 13:30:38 · 310 阅读 · 0 评论 -
开始刷leetcode day49: 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.原创 2015-06-25 11:26:00 · 350 阅读 · 0 评论 -
开始刷leetcode day42:Search in Rotated Sorted Array
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 retur原创 2015-06-16 11:16:55 · 260 阅读 · 0 评论 -
开始刷leetcode day15: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 val原创 2015-05-18 13:54:12 · 241 阅读 · 0 评论 -
开始刷leetcode day15:Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2015-05-18 13:30:59 · 236 阅读 · 0 评论 -
开始刷题leetcode day47: Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.java: publ转载 2015-06-22 11:01:12 · 427 阅读 · 0 评论 -
开始刷leetcode day47: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-06-22 11:38:21 · 293 阅读 · 0 评论 -
开始刷leetcode day47: 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"转载 2015-06-22 13:37:05 · 343 阅读 · 0 评论 -
开始刷leetcode day29:Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2015-06-02 10:24:35 · 311 阅读 · 0 评论 -
开始刷leetcode day31:Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext转载 2015-06-04 12:11:42 · 299 阅读 · 0 评论 -
开始刷leetcode day30:Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2015-06-03 14:57:36 · 345 阅读 · 0 评论 -
Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For原创 2015-07-12 04:19:18 · 293 阅读 · 0 评论 -
开始刷leetcode day63:Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howell原创 2015-07-13 05:16:07 · 274 阅读 · 0 评论 -
开始刷leetcode day79:Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2015-07-28 13:00:33 · 407 阅读 · 0 评论 -
开始刷leetcode day71:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2015-07-19 10:48:42 · 571 阅读 · 0 评论 -
开始刷leetcode day71: Power of Two
Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.Java:public c原创 2015-07-19 10:09:56 · 392 阅读 · 0 评论 -
开始刷leetcode day71:Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Credits:Special thanks to @jianchao.li.fighter原创 2015-07-19 10:43:03 · 294 阅读 · 0 评论 -
开始刷leetcode day72: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 solut原创 2015-07-20 10:33:46 · 345 阅读 · 0 评论 -
开始刷leetcode day72: Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2015-07-20 10:40:49 · 349 阅读 · 0 评论 -
开始刷leetcode day72: Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the转载 2015-07-20 09:14:53 · 469 阅读 · 0 评论 -
开始刷leedtcode day72:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O转载 2015-07-20 09:57:42 · 529 阅读 · 0 评论 -
leetcode: Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2015-10-12 03:11:09 · 435 阅读 · 0 评论 -
开始刷leetcode day78:Binary Search Tree Iterator
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()原创 2015-07-27 12:21:44 · 368 阅读 · 0 评论 -
开始刷leetcode day59: Unique Paths
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原创 2015-07-06 11:20:17 · 305 阅读 · 0 评论 -
开始刷leetcode day63: Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2015-07-13 05:23:00 · 307 阅读 · 0 评论 -
开始刷leetcode day63:Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(原创 2015-07-13 05:08:02 · 288 阅读 · 0 评论 -
开始刷leetcode day63:Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at most原创 2015-07-13 05:28:51 · 270 阅读 · 0 评论 -
开始刷leetcode day63:Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an转载 2015-07-13 06:04:55 · 330 阅读 · 0 评论 -
开始刷leetcode day63:House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time转载 2015-07-13 06:42:12 · 357 阅读 · 0 评论 -
开始刷leetcode day41:Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updated原创 2015-06-15 09:47:10 · 276 阅读 · 0 评论