07 2015 档案

摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文
posted @ 2015-07-28 00:19 ~每天进步一点点~ 阅读(160) 评论(0) 推荐(0)
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1]./*... 阅读全文
posted @ 2015-07-27 13:08 ~每天进步一点点~ 阅读(135) 评论(0) 推荐(0)
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]./**... 阅读全文
posted @ 2015-07-26 23:13 ~每天进步一点点~ 阅读(133) 评论(0) 推荐(0)
摘要:Given a singly linked listL: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 exam... 阅读全文
posted @ 2015-07-26 22:57 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?因为f... 阅读全文
posted @ 2015-07-26 22:21 ~每天进步一点点~ 阅读(92) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. *... 阅读全文
posted @ 2015-07-26 21:55 ~每天进步一点点~ 阅读(114) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possibl... 阅读全文
posted @ 2015-07-26 20:46 ~每天进步一点点~ 阅读(213) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2015-07-26 20:09 ~每天进步一点点~ 阅读(134) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2015-07-26 19:53 ~每天进步一点点~ 阅读(132) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one.public class Solution { public int singleNumber(in... 阅读全文
posted @ 2015-07-26 18:50 ~每天进步一点点~ 阅读(166) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文
posted @ 2015-07-26 17:01 ~每天进步一点点~ 阅读(128) 评论(0) 推荐(0)
摘要:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2015-07-26 16:58 ~每天进步一点点~ 阅读(160) 评论(0) 推荐(0)
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2015-07-26 16:36 ~每天进步一点点~ 阅读(889) 评论(0) 推荐(1)
摘要:Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniq... 阅读全文
posted @ 2015-07-26 15:56 ~每天进步一点点~ 阅读(153) 评论(0) 推荐(0)
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文
posted @ 2015-07-26 14:53 ~每天进步一点点~ 阅读(199) 评论(0) 推荐(0)
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, giv... 阅读全文
posted @ 2015-07-26 13:51 ~每天进步一点点~ 阅读(122) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-26 12:55 ~每天进步一点点~ 阅读(149) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep... 阅读全文
posted @ 2015-07-24 22:13 ~每天进步一点点~ 阅读(134) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2015-07-24 21:54 ~每天进步一点点~ 阅读(155) 评论(0) 推荐(0)
摘要:Given two words (beginWordandendWord), and a dictionary, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only on... 阅读全文
posted @ 2015-07-24 21:28 ~每天进步一点点~ 阅读(101) 评论(0) 推荐(0)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文
posted @ 2015-07-24 20:35 ~每天进步一点点~ 阅读(145) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2015-07-24 20:24 ~每天进步一点点~ 阅读(109) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2015-07-24 19:11 ~每天进步一点点~ 阅读(146) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2015-07-23 23:45 ~每天进步一点点~ 阅读(106) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2015-07-23 23:35 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol... 阅读全文
posted @ 2015-07-22 22:45 ~每天进步一点点~ 阅读(125) 评论(0) 推荐(0)
摘要:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].public class Solution { public List getRow(int ro... 阅读全文
posted @ 2015-07-22 22:18 ~每天进步一点点~ 阅读(140) 评论(0) 推荐(0)
摘要:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]... 阅读全文
posted @ 2015-07-22 21:58 ~每天进步一点点~ 阅读(125) 评论(0) 推荐(0)
摘要:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil... 阅读全文
posted @ 2015-07-22 21:33 ~每天进步一点点~ 阅读(148) 评论(0) 推荐(0)
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe... 阅读全文
posted @ 2015-07-22 21:10 ~每天进步一点点~ 阅读(155) 评论(0) 推荐(0)
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2015-07-22 20:49 ~每天进步一点点~ 阅读(141) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文
posted @ 2015-07-22 20:11 ~每天进步一点点~ 阅读(127) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =... 阅读全文
posted @ 2015-07-22 18:48 ~每天进步一点点~ 阅读(113) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo... 阅读全文
posted @ 2015-07-22 17:54 ~每天进步一点点~ 阅读(121) 评论(0) 推荐(0)
摘要: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 le... 阅读全文
posted @ 2015-07-22 13:10 ~每天进步一点点~ 阅读(152) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth... 阅读全文
posted @ 2015-07-21 23:47 ~每天进步一点点~ 阅读(181) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. ... 阅读全文
posted @ 2015-07-21 23:18 ~每天进步一点点~ 阅读(108) 评论(0) 推荐(0)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * public cla... 阅读全文
posted @ 2015-07-21 22:51 ~每天进步一点点~ 阅读(100) 评论(0) 推荐(0)
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文
posted @ 2015-07-21 22:41 ~每天进步一点点~ 阅读(127) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definiti... 阅读全文
posted @ 2015-07-21 21:39 ~每天进步一点点~ 阅读(135) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definitio... 阅读全文
posted @ 2015-07-21 21:12 ~每天进步一点点~ 阅读(190) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2015-07-21 18:34 ~每天进步一点点~ 阅读(93) 评论(0) 推荐(0)
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2015-07-20 21:55 ~每天进步一点点~ 阅读(117) 评论(0) 推荐(0)
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文
posted @ 2015-07-20 21:50 ~每天进步一点点~ 阅读(147) 评论(0) 推荐(0)
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2015-07-20 21:18 ~每天进步一点点~ 阅读(148) 评论(0) 推荐(0)
摘要: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 / \ ... 阅读全文
posted @ 2015-07-20 16:59 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2015-07-16 23:08 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2015-07-16 23:03 ~每天进步一点点~ 阅读(200) 评论(0) 推荐(0)
摘要: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 n... 阅读全文
posted @ 2015-07-16 22:17 ~每天进步一点点~ 阅读(129) 评论(0) 推荐(0)
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文
posted @ 2015-07-16 21:58 ~每天进步一点点~ 阅读(228) 评论(0) 推荐(0)
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文
posted @ 2015-07-16 20:51 ~每天进步一点点~ 阅读(174) 评论(0) 推荐(0)
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1... 阅读全文
posted @ 2015-07-16 18:16 ~每天进步一点点~ 阅读(151) 评论(0) 推荐(0)
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文
posted @ 2015-07-16 17:19 ~每天进步一点点~ 阅读(111) 评论(0) 推荐(0)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2015-07-16 16:49 ~每天进步一点点~ 阅读(176) 评论(0) 推荐(0)
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2015-07-16 15:59 ~每天进步一点点~ 阅读(155) 评论(0) 推荐(0)
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2015-07-16 15:07 ~每天进步一点点~ 阅读(240) 评论(0) 推荐(0)
摘要:Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note:Elements in a subset must be in non-descending ord... 阅读全文
posted @ 2015-07-16 12:33 ~每天进步一点点~ 阅读(202) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number... 阅读全文
posted @ 2015-07-16 12:04 ~每天进步一点点~ 阅读(158) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-07-16 11:42 ~每天进步一点点~ 阅读(118) 评论(0) 推荐(0)
摘要:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation... 阅读全文
posted @ 2015-07-15 23:53 ~每天进步一点点~ 阅读(265) 评论(0) 推荐(0)
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文
posted @ 2015-07-15 22:27 ~每天进步一点点~ 阅读(228) 评论(1) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.public class Solution { public... 阅读全文
posted @ 2015-07-15 21:06 ~每天进步一点点~ 阅读(183) 评论(0) 推荐(0)
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文
posted @ 2015-07-15 19:55 ~每天进步一点点~ 阅读(138) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2015-07-15 16:31 ~每天进步一点点~ 阅读(187) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2015-07-15 12:03 ~每天进步一点点~ 阅读(132) 评论(0) 推荐(0)
摘要:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to... 阅读全文
posted @ 2015-07-15 11:34 ~每天进步一点点~ 阅读(136) 评论(0) 推荐(0)
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted arraynums=[1,1,1,2,2,3],Your function should re... 阅读全文
posted @ 2015-07-14 23:13 ~每天进步一点点~ 阅读(111) 评论(0) 推荐(0)
摘要:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjace... 阅读全文
posted @ 2015-07-14 22:37 ~每天进步一点点~ 阅读(174) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-14 21:29 ~每天进步一点点~ 阅读(158) 评论(0) 推荐(0)
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2015-07-14 19:23 ~每天进步一点点~ 阅读(139) 评论(0) 推荐(0)
摘要: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="ADOBECODEBA... 阅读全文
posted @ 2015-07-14 19:10 ~每天进步一点点~ 阅读(147) 评论(0) 推荐(0)
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-07-14 18:08 ~每天进步一点点~ 阅读(111) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2015-07-14 17:25 ~每天进步一点点~ 阅读(153) 评论(0) 推荐(0)
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.public class Solution { public void setZeroes(int[][] matr... 阅读全文
posted @ 2015-07-14 17:10 ~每天进步一点点~ 阅读(145) 评论(0) 推荐(0)
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"public class Solution { ... 阅读全文
posted @ 2015-07-13 23:02 ~每天进步一点点~ 阅读(174) 评论(0) 推荐(0)
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文
posted @ 2015-07-13 22:22 ~每天进步一点点~ 阅读(113) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.public class Solution { //本题利用了牛顿迭代法:设r是f(x) = 0的根(x^2-k=f(x)),选取x0作为r初始近似值,过点(x0,f... 阅读全文
posted @ 2015-07-13 22:08 ~每天进步一点点~ 阅读(186) 评论(0) 推荐(0)
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".public class Solution { public String addBin... 阅读全文
posted @ 2015-07-13 21:34 ~每天进步一点点~ 阅读(101) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-13 18:10 ~每天进步一点点~ 阅读(147) 评论(0) 推荐(0)
摘要:Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem stat... 阅读全文
posted @ 2015-07-13 17:56 ~每天进步一点点~ 阅读(213) 评论(0) 推荐(0)
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2015-07-13 16:19 ~每天进步一点点~ 阅读(126) 评论(0) 推荐(0)
摘要: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 i... 阅读全文
posted @ 2015-07-13 15:43 ~每天进步一点点~ 阅读(195) 评论(0) 推荐(0)
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2015-07-13 14:35 ~每天进步一点点~ 阅读(132) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL./** *... 阅读全文
posted @ 2015-07-13 14:21 ~每天进步一点点~ 阅读(163) 评论(0) 推荐(0)
摘要:The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie... 阅读全文
posted @ 2015-07-13 12:39 ~每天进步一点点~ 阅读(296) 评论(0) 推荐(0)
摘要:Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri... 阅读全文
posted @ 2015-07-13 10:52 ~每天进步一点点~ 阅读(130) 评论(0) 推荐(0)
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe... 阅读全文
posted @ 2015-07-13 10:43 ~每天进步一点点~ 阅读(115) 评论(0) 推荐(0)
摘要: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]./** * Definiti... 阅读全文
posted @ 2015-07-12 23:47 ~每天进步一点点~ 阅读(115) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文
posted @ 2015-07-12 23:19 ~每天进步一点点~ 阅读(95) 评论(0) 推荐(0)
摘要:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ],... 阅读全文
posted @ 2015-07-12 21:48 ~每天进步一点点~ 阅读(169) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2015-07-12 21:25 ~每天进步一点点~ 阅读(163) 评论(0) 推荐(0)
摘要:首先对要求的数进行质因数分解,然后求各因数的幂的积数,比如600=2^3*3^1*5^2那么因子个数是(3+1)*(1+1)*(2+1)=24public class TestYuman{ public static void main(String[] args){ i... 阅读全文
posted @ 2015-07-12 20:52 ~每天进步一点点~ 阅读(1256) 评论(0) 推荐(0)
摘要: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 maximu... 阅读全文
posted @ 2015-07-12 15:56 ~每天进步一点点~ 阅读(125) 评论(0) 推荐(0)
摘要:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.public class Solution { ... 阅读全文
posted @ 2015-07-12 15:46 ~每天进步一点点~ 阅读(104) 评论(0) 推荐(0)
摘要:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc... 阅读全文
posted @ 2015-07-12 15:31 ~每天进步一点点~ 阅读(134) 评论(0) 推荐(0)
摘要:public class Solution { public double myPow(double x, int n) { //利用二分法,通过递归加速计算 //注意:1.判断n是否为负 // 2.递归结束条件,n==1和n==0 //... 阅读全文
posted @ 2015-07-12 14:19 ~每天进步一点点~ 阅读(106) 评论(0) 推荐(0)
摘要:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.public class Solution { public Lis... 阅读全文
posted @ 2015-07-12 13:59 ~每天进步一点点~ 阅读(178) 评论(0) 推荐(0)
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?In order to fulfill... 阅读全文
posted @ 2015-07-11 12:53 ~每天进步一点点~ 阅读(146) 评论(0) 推荐(0)
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique perm... 阅读全文
posted @ 2015-07-11 11:54 ~每天进步一点点~ 阅读(225) 评论(0) 推荐(0)
摘要:Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,... 阅读全文
posted @ 2015-07-11 11:03 ~每天进步一点点~ 阅读(143) 评论(0) 推荐(0)
摘要: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 maximu... 阅读全文
posted @ 2015-07-11 09:32 ~每天进步一点点~ 阅读(113) 评论(0) 推荐(0)
摘要:Straight forward idea. Just like the way we multiply numbers. Don't forget considering the carry and be careful. e.g. 123*456,what we usually do is: ... 阅读全文
posted @ 2015-07-10 22:18 ~每天进步一点点~ 阅读(162) 评论(0) 推荐(0)
摘要:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文
posted @ 2015-07-10 18:20 ~每天进步一点点~ 阅读(209) 评论(0) 推荐(0)
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文
posted @ 2015-07-10 17:17 ~每天进步一点点~ 阅读(181) 评论(0) 推荐(0)
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文
posted @ 2015-07-10 15:59 ~每天进步一点点~ 阅读(168) 评论(0) 推荐(0)
摘要:public class Quanpailie { /** * 全排列的思想,第一位和后面的每一位进行交换,然后递归下一位 * combinate(int a[],int start,int end) * 参数的意思是从第start位开始到end位进行全排列 *... 阅读全文
posted @ 2015-07-10 15:33 ~每天进步一点点~ 阅读(196) 评论(0) 推荐(0)
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num... 阅读全文
posted @ 2015-07-10 15:27 ~每天进步一点点~ 阅读(203) 评论(0) 推荐(0)
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw... 阅读全文
posted @ 2015-07-10 14:15 ~每天进步一点点~ 阅读(128) 评论(0) 推荐(0)
摘要:Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with ... 阅读全文
posted @ 2015-07-09 22:52 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2015-07-09 18:25 ~每天进步一点点~ 阅读(123) 评论(0) 推荐(0)
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2015-07-09 18:09 ~每天进步一点点~ 阅读(134) 评论(0) 推荐(0)
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文
posted @ 2015-07-09 17:46 ~每天进步一点点~ 阅读(101) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest... 阅读全文
posted @ 2015-07-09 16:59 ~每天进步一点点~ 阅读(102) 评论(0) 推荐(0)
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2015-07-09 15:59 ~每天进步一点点~ 阅读(138) 评论(0) 推荐(0)
摘要:You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a concatena... 阅读全文
posted @ 2015-07-09 14:13 ~每天进步一点点~ 阅读(171) 评论(0) 推荐(0)
摘要:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INTpublic class Solution { //本题很多细节需要考虑: ... 阅读全文
posted @ 2015-07-08 22:57 ~每天进步一点点~ 阅读(182) 评论(0) 推荐(0)
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.public class Solution { ... 阅读全文
posted @ 2015-07-08 21:58 ~每天进步一点点~ 阅读(131) 评论(0) 推荐(0)
摘要: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 mat... 阅读全文
posted @ 2015-07-08 21:24 ~每天进步一点点~ 阅读(150) 评论(0) 推荐(0)
摘要:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a... 阅读全文
posted @ 2015-07-08 21:06 ~每天进步一点点~ 阅读(97) 评论(0) 推荐(0)
摘要:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-o... 阅读全文
posted @ 2015-07-08 18:11 ~每天进步一点点~ 阅读(200) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2015-07-08 13:55 ~每天进步一点点~ 阅读(134) 评论(0) 推荐(0)
摘要:public class Solution { //卡特兰数,一共有C2n^n-C2n^n-1种组合数 //本题的递归非常经典,需要多看牢记 List res; StringBuilder seq; public List generateParenthesis(int... 阅读全文
posted @ 2015-07-07 22:52 ~每天进步一点点~ 阅读(118) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public... 阅读全文
posted @ 2015-07-07 22:19 ~每天进步一点点~ 阅读(192) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public... 阅读全文
posted @ 2015-07-07 18:25 ~每天进步一点点~ 阅读(150) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2015-07-07 17:51 ~每天进步一点点~ 阅读(108) 评论(0) 推荐(0)
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文
posted @ 2015-07-07 15:39 ~每天进步一点点~ 阅读(88) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文
posted @ 2015-07-07 15:14 ~每天进步一点点~ 阅读(131) 评论(0) 推荐(0)
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon... 阅读全文
posted @ 2015-07-07 13:36 ~每天进步一点点~ 阅读(138) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2015-07-07 11:27 ~每天进步一点点~ 阅读(169) 评论(0) 推荐(0)
摘要:public class Solution { public List> threeSum(int[] nums) { //本题需要对重复数字进行考虑,主要涉及以下几处: //1.外层循环时,需要与前一个数进行比较,如果重复,使用 if 和continue ... 阅读全文
posted @ 2015-07-06 22:56 ~每天进步一点点~ 阅读(192) 评论(0) 推荐(0)
摘要:public class Solution { public String longestCommonPrefix(String[] strs) { //求公共子序列,公共子序列必须是str[0]的子串,因此本题是将每一个字符串按位和第一个字符串的每一位进行比较 /... 阅读全文
posted @ 2015-07-06 22:03 ~每天进步一点点~ 阅读(119) 评论(0) 推荐(0)
摘要:public class Solution { public int maxArea(int[] height) { /* 题意:二维坐标系里有 n 个点 (i, ai), ai >= 0,从 (i, ai)到(i, 0)划竖线,共有 n 条竖线。 找出两条竖线,使得... 阅读全文
posted @ 2015-07-06 21:15 ~每天进步一点点~ 阅读(116) 评论(0) 推荐(0)
摘要:Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The... 阅读全文
posted @ 2015-07-06 20:41 ~每天进步一点点~ 阅读(143) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isPalindrome(int x) { //负数不是回文 //主要的突破点是如何获得整数的第n位和后n位(/和%运算结合) if(x=10){//这里面需要考虑整数越界的... 阅读全文
posted @ 2015-07-06 18:55 ~每天进步一点点~ 阅读(115) 评论(0) 推荐(0)
摘要:public class Solution { public int myAtoi(String str) { //此题需要注意的细节很多 //1.对于“ -123”,“ +3231”,需要考虑去除最前的空格,主要利用循环 //2.对于越界情况需要判... 阅读全文
posted @ 2015-07-05 22:56 ~每天进步一点点~ 阅读(163) 评论(0) 推荐(0)
摘要:public class Solution { public int reverse(int x) { //此题需要注意整数越界问题,因此先将res声明为long,注意32位的范围是0x80000000到0x7fffffff long res=0; i... 阅读全文
posted @ 2015-07-04 22:51 ~每天进步一点点~ 阅读(135) 评论(0) 推荐(0)
摘要:public class Solution { public String convert(String s, int numRows) { //本题通过画图numRows=4和numRows=5可以得到规则,主线路距离是2*numRows-2;辅助行是(numRows-i-1)... 阅读全文
posted @ 2015-07-04 22:26 ~每天进步一点点~ 阅读(144) 评论(0) 推荐(0)
摘要:public class Solution { public String longestPalindrome(String s) { //本题是动态规划思想,构造一个数组pal[i][j],表示从i到j是否为一个回文, //pal[i][j]=true;if i=... 阅读全文
posted @ 2015-07-04 21:40 ~每天进步一点点~ 阅读(149) 评论(0) 推荐(0)
摘要:There are two sorted arraysnums1andnums2of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should... 阅读全文
posted @ 2015-07-04 16:09 ~每天进步一点点~ 阅读(167) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2015-07-04 14:03 ~每天进步一点点~ 阅读(133) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2015-07-03 23:46 ~每天进步一点点~ 阅读(161) 评论(0) 推荐(0)
摘要: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 nu... 阅读全文
posted @ 2015-07-03 23:16 ~每天进步一点点~ 阅读(136) 评论(0) 推荐(0)
摘要: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 t... 阅读全文
posted @ 2015-07-03 21:46 ~每天进步一点点~ 阅读(247) 评论(0) 推荐(0)
摘要:public class SecondMax { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ... 阅读全文
posted @ 2015-07-03 16:55 ~每天进步一点点~ 阅读(205) 评论(0) 推荐(0)
摘要:一个全是数字的大数组,除了其中一个数字出现2次外,其余的数字都出现了3次。如何找出那个只出现了两次的数字?其中ones记录了所有出现了模3余1次的bit,twos记录的是余2的。not_threes是当一个bit出现第3次的时候,把它清掉。public class Test3in2 { /**... 阅读全文
posted @ 2015-07-02 16:47 ~每天进步一点点~ 阅读(378) 评论(0) 推荐(0)