08 2015 档案

摘要:百度:1.从键盘输入一个字符串,长度未知,然后输出所有的全排列。例如输入abc, 输出abc,acb,bac,bca,cab,cba这样。很遗憾,当时思路不清晰,说了半天没说出个所以然。不知道这种题目对于大家来说是不是很简单,一下就做出来了。2.生日悖论问题。不知道自己去百度吧。这个问题其实很简单的... 阅读全文
posted @ 2015-08-29 21:55 irun 阅读(192) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution 1: recursionruntime: 28ms./** * ... 阅读全文
posted @ 2015-08-25 23:42 irun 阅读(174) 评论(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-08-23 22:58 irun 阅读(176) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Hide Tags:Linked ListTwo PointersHide Simi... 阅读全文
posted @ 2015-08-18 16:23 irun 阅读(89) 评论(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?Sol... 阅读全文
posted @ 2015-08-18 16:22 irun 阅读(186) 评论(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-08-18 15:07 irun 阅读(141) 评论(0) 推荐(0)
摘要:Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3 + ... 阅读全文
posted @ 2015-08-16 23:56 irun 阅读(326) 评论(0) 推荐(0)
摘要:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->... 阅读全文
posted @ 2015-08-16 16:53 irun 阅读(1164) 评论(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-08-16 16:21 irun 阅读(140) 评论(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-08-16 15:51 irun 阅读(120) 评论(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-08-15 21:34 irun 阅读(144) 评论(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-08-15 20:53 irun 阅读(137) 评论(0) 推荐(0)
摘要:Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRules.aspx)The Sudoku board could be partially filled... 阅读全文
posted @ 2015-08-13 23:50 irun 阅读(214) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-08-12 23:17 irun 阅读(146) 评论(0) 推荐(0)
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Solution: 1 class Solution... 阅读全文
posted @ 2015-08-12 23:06 irun 阅读(118) 评论(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-08-11 23:38 irun 阅读(248) 评论(0) 推荐(0)
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-08-11 23:07 irun 阅读(151) 评论(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-08-11 00:01 irun 阅读(169) 评论(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-08-10 23:44 irun 阅读(141) 评论(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-08-10 23:15 irun 阅读(134) 评论(0) 推荐(0)
摘要:118 - Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], ... 阅读全文
posted @ 2015-08-10 21:09 irun 阅读(170) 评论(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-08-10 00:30 irun 阅读(144) 评论(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-08-10 00:12 irun 阅读(155) 评论(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-08-09 23:08 irun 阅读(161) 评论(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-08-09 22:30 irun 阅读(145) 评论(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-08-09 20:01 irun 阅读(153) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.Solution: 1 class Solution { 2 public: 3 string longestCommo... 阅读全文
posted @ 2015-08-08 23:54 irun 阅读(150) 评论(0) 推荐(0)
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1sum2)return 1;16 else if(sum1<sum2)return -1;17 ... 阅读全文
posted @ 2015-08-08 21:10 irun 阅读(122) 评论(0) 推荐(0)
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes... 阅读全文
posted @ 2015-08-08 20:14 irun 阅读(125) 评论(0) 推荐(0)
摘要:12- Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Solution: 枚举,考虑每个字符以及每两个... 阅读全文
posted @ 2015-08-08 00:05 irun 阅读(176) 评论(0) 推荐(0)
摘要:66 - Plus OneGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significan... 阅读全文
posted @ 2015-08-06 23:38 irun 阅读(186) 评论(0) 推荐(0)
摘要:168 - Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 ... 阅读全文
posted @ 2015-08-06 23:05 irun 阅读(134) 评论(0) 推荐(0)
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.Solution :计算包含的2和5组成的pair的个数,... 阅读全文
posted @ 2015-08-05 17:59 irun 阅读(127) 评论(0) 推荐(0)
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-08-04 22:53 irun 阅读(333) 评论(0) 推荐(0)
摘要:190 - Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110... 阅读全文
posted @ 2015-08-04 00:06 irun 阅读(159) 评论(0) 推荐(0)
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo... 阅读全文
posted @ 2015-08-03 23:28 irun 阅读(162) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2015-08-02 21:56 irun 阅读(125) 评论(0) 推荐(0)
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2015-08-02 21:11 irun 阅读(136) 评论(0) 推荐(0)
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ... 阅读全文
posted @ 2015-08-02 20:08 irun 阅读(144) 评论(0) 推荐(0)
摘要:217 - Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears a... 阅读全文
posted @ 2015-08-02 15:00 irun 阅读(152) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9 to 4 / \ 7 2 / \ / \9 6 3 1Notice:Google: 90% of our engineers... 阅读全文
posted @ 2015-08-02 14:16 irun 阅读(124) 评论(0) 推荐(0)
摘要:Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", retur... 阅读全文
posted @ 2015-08-02 13:56 irun 阅读(153) 评论(0) 推荐(0)
摘要:232 - Implement Queue using StacksImplement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- R... 阅读全文
posted @ 2015-08-02 13:11 irun 阅读(146) 评论(0) 推荐(0)