- 博客(241)
- 资源 (8)
- 收藏
- 关注
原创 Leetcode 300. Longest Increasing Subsequence
原题:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], therefore...
2018-03-02 09:25:24 213
原创 Leetcode 263. Ugly Number
原题: Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since ...
2018-03-02 09:25:19 210
原创 Leetcode 299. Bulls and Cows
原题: You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint...
2018-03-02 09:25:12 208
原创 297. Serialize and Deserialize Binary Tree
原题: Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link t...
2018-03-02 09:25:07 171
原创 Leetcode 295. Find Median from Data Stream
原题: Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median i...
2018-03-02 09:25:02 175
原创 Leetcode 292. Nim Game
原题: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be...
2018-03-02 09:24:55 133
原创 Leetcode 290. 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.Examp...
2018-03-02 09:24:50 133
原创 Leetcode 289. Game of Life
原题: According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by...
2018-03-02 09:24:45 134
原创 Leetcode 287. Find the Duplicate Number
原题: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number...
2018-03-02 09:24:39 125
原创 Leetcode 284. Peeking Iterator
原题: Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be ...
2018-03-02 09:24:34 111
原创 Leetcode 283. Move Zeroes
原题: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your...
2018-03-02 09:24:27 134
原创 Leetcode 282. Expression Add Operators
原题: Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.Exa...
2018-03-02 09:24:20 186
原创 Leetcode 279. Perfect Squares
原题: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,...
2018-03-02 09:24:09 134
原创 Leetcode 278. First Bad Version
原题: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on...
2018-03-02 09:24:03 145
原创 Leetcode 275. H-Index II
原题: Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? 解决方法: 由于已经排序,不需要再次排序,只需二分查找即可。 代码: int hIndex(vector<int>& citations) ...
2018-03-02 09:23:57 307
原创 Leetcode 274. H-Index
原题: Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A ...
2018-03-02 09:23:52 189
原创 Leetcode 273. Integer to English Words
原题: Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand ...
2018-03-02 09:23:47 154
原创 Leetcode 260. Single Number III
原题: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums =...
2018-03-02 09:23:41 97
原创 Leetcode 258. Add Digits
原题: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one di...
2018-03-02 09:23:35 102
原创 Leetcode 257. Binary Tree Paths
原题: 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->2->5", "1->3"] 解决方法: 采用dfs的递归方法:...
2018-03-01 14:43:20 156
原创 Leetcode 242. Valid Anagram
原题: Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assume the s...
2018-03-01 14:43:14 94
原创 Leetcode 241. Different Ways to Add Parentheses
原题: Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1Inpu...
2018-03-01 14:43:07 99
原创 Leetcode 240. Search a 2D Matrix II
原题: 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 in ascending from left to right.Integers in each...
2018-03-01 14:43:03 102
原创 Leetcode 239. Sliding Window Maximum
原题: Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding wind...
2018-03-01 14:42:57 103
原创 Leetcode 238. 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(...
2018-03-01 14:42:51 165
原创 Leetcode 237. 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 w...
2018-03-01 14:42:46 88
原创 Leetcode 236. Lowest Common Ancestor of a Binary Tree
原题: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes ...
2018-03-01 14:42:40 92
原创 Leetcode 235. 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 betwee...
2018-03-01 14:42:34 86
原创 Leetcode 234. Palindrome Linked List
原题: Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space? 解决方法:- 用快慢指针,将链表分成前后两部分;- 将后半部分倒序;- 依次比较两部分节点的值。 代码: bool isPalindrome(ListNode* ...
2018-03-01 14:42:28 98
原创 Leetcode 233. Number of Digit One
原题: Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example: Given n = 13,Return 6, because digit 1 occurred in the following n...
2018-03-01 14:42:23 100
原创 Leetcode 232. 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(...
2018-03-01 14:42:06 110
原创 Leetcode 231. Power of Two
原题: Given an integer, write a function to determine if it is a power of two. 解决方法: 去掉最低位,看看是不是0即可。 代码: bool isPowerOfTwo(int n) { return n > 0 && (!(n &(n-1))); } ...
2018-03-01 14:42:00 80
原创 Leetcode 230. 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 BST is mo...
2018-02-28 15:22:42 108
原创 Leetcode 229. Majority Element II
原题: Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 解决方法: 用类似于Majority Element的解法,用计数的办法找到重复最多的那两个数,...
2018-02-28 15:22:37 99
原创 Leetcode 228. Summary Ranges
原题:Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Example 2:Input: [0,2,3,4,6,8,9]Output: ["0","2-&
2018-02-28 15:22:32 115
原创 Leetcode 227. Basic Calculator II
原题:Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should t...
2018-02-28 15:22:27 100
原创 Leetcode 226. 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:Google: ...
2018-02-28 15:22:21 84
原创 Leetcode 225. Implement Stack using Queues
原题:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return wheth...
2018-02-28 15:22:15 88
原创 Leetcode 224. Basic Calculator
原题:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty s...
2018-02-28 15:22:10 143
原创 Leetcode 223. 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 total area is...
2018-02-28 15:21:57 109
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人