随笔分类 -  LeetCode 题目

202. Happy Number
摘要: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-04-22 11:39 shini 阅读(124) 评论(0) 推荐(0)

141. 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?Cracking Interview书上原题,快慢指针,如果有环肯定相遇。/** *... 阅读全文

posted @ 2015-04-18 08:14 shini 阅读(110) 评论(0) 推荐(0)

142. Linked List Cycle II
摘要: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?Cra... 阅读全文

posted @ 2015-04-18 08:11 shini 阅读(105) 评论(0) 推荐(0)

143. Reorder List
摘要: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-04-18 08:06 shini 阅读(87) 评论(0) 推荐(0)

94. Binary Tree Inorder Traversal
摘要: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-04-18 07:18 shini 阅读(93) 评论(0) 推荐(0)

144. Binary Tree Preorder Traversal
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].先pu... 阅读全文

posted @ 2015-04-18 06:55 shini 阅读(90) 评论(0) 推荐(0)

145. Binary Tree Postorder Traversal
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文

posted @ 2015-04-18 06:39 shini 阅读(138) 评论(0) 推荐(0)

201. Bitwise AND of Numbers Range
摘要:Given a range [m, n] where 0 > 1; while (s != 0) { a |= s; s >>= 1; } return m&n&~a... 阅读全文

posted @ 2015-04-17 01:00 shini 阅读(138) 评论(0) 推荐(0)

146. LRU Cache
摘要: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-04-16 05:22 shini 阅读(158) 评论(0) 推荐(0)

148. Sort List
摘要:Sort a linked list inO(nlogn) time using constant space complexity.Merge Sort./** * Definition for singly-linked list. * class ListNode { * int ... 阅读全文

posted @ 2015-04-16 04:33 shini 阅读(84) 评论(0) 推荐(0)

150. Evaluate Reverse Polish Notation
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文

posted @ 2015-04-15 02:53 shini 阅读(74) 评论(0) 推荐(0)

151. Reverse Words in a String
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C prog... 阅读全文

posted @ 2015-04-15 02:42 shini 阅读(98) 评论(0) 推荐(0)

152. Maximum Product Subarray
摘要: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-04-15 02:22 shini 阅读(110) 评论(0) 推荐(0)

153. Find Minimum 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 7might become4 5 6 7 0 1 2).Find the minimum element.You m... 阅读全文

posted @ 2015-04-15 02:03 shini 阅读(95) 评论(0) 推荐(0)

154. Find Minimum in Rotated Sorted Array II
摘要:Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sort... 阅读全文

posted @ 2015-04-15 02:01 shini 阅读(98) 评论(0) 推荐(0)

155. Min Stack
摘要: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-04-15 01:45 shini 阅读(126) 评论(0) 推荐(0)

160. Intersection of Two Linked Lists
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a... 阅读全文

posted @ 2015-04-14 11:25 shini 阅读(106) 评论(0) 推荐(0)

162. Find Peak Element
摘要:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文

posted @ 2015-04-14 11:09 shini 阅读(112) 评论(0) 推荐(0)

168. Excel Sheet Column Title
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... 阅读全文

posted @ 2015-04-13 08:37 shini 阅读(97) 评论(0) 推荐(0)

169. Majority Element
摘要: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-04-13 08:34 shini 阅读(219) 评论(0) 推荐(0)

导航