
leetcode
_我们的存在
这个作者很懒,什么都没留下…
展开
-
LeetCode题目汇总
我的博客:http://blog.youkuaiyun.com/yano_nankai LeetCode题解:https://github.com/LjyYano/LeetCodeLeetCode之Array题目汇总 LeetCode之Hash Table题目汇总 LeetCode之Linked List题目汇总 LeetCode之Math题目汇总 LeetCode之String题目汇总 Leet原创 2016-01-03 10:38:00 · 1539 阅读 · 0 评论 -
LeetCode之Design题目汇总
Implement Queue using StacksImplement 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 t原创 2015-12-30 10:39:53 · 1583 阅读 · 2 评论 -
LeetCode之Trie题目汇总
Implement Trie (Prefix Tree)Implement a trie with insert, search, and startsWith methods.Note: You may assume that all inputs are consist of lowercase letters a-z. class TrieNode { boolean i原创 2015-12-30 10:28:37 · 1024 阅读 · 0 评论 -
LeetCode之Graph题目汇总
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expre原创 2015-12-30 10:25:11 · 1107 阅读 · 0 评论 -
LeetCode之Breadth-first Search题目汇总
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree {3,9,20,#,#,15,7},原创 2015-12-30 10:21:34 · 780 阅读 · 0 评论 -
LeetCode之Depth-first Search题目汇总
Balanced Binary TreeGiven 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 of the two subtrees of every n原创 2015-12-30 09:57:11 · 896 阅读 · 0 评论 -
LeetCode之Tree题目汇总
Balanced Binary TreeGiven 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 of the two subtrees of every n原创 2015-12-29 20:43:14 · 1878 阅读 · 0 评论 -
LeetCode之Bit Manipulation题目汇总
Bitwise AND of Numbers RangeGiven a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4原创 2015-12-29 18:41:44 · 1010 阅读 · 0 评论 -
LeetCode之Sort题目汇总
H-IndexGiven 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: “原创 2015-12-29 18:19:56 · 1019 阅读 · 0 评论 -
LeetCode之Stack题目汇总
Basic CalculatorImplement 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原创 2015-12-29 16:58:31 · 1166 阅读 · 0 评论 -
LeetCode之Backtracing题目汇总
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimi原创 2015-12-29 13:18:37 · 722 阅读 · 0 评论 -
LeetCode之Dynamic Programming题目汇总
Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sel原创 2015-12-27 23:01:25 · 906 阅读 · 0 评论 -
LeetCode之Divide and Conquer题目汇总
Different Ways to Add ParenthesesGiven 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原创 2015-12-27 22:25:57 · 972 阅读 · 0 评论 -
LeetCode之Binary Search题目汇总
Count Complete Tree NodesGiven a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, i原创 2015-12-27 21:46:54 · 627 阅读 · 0 评论 -
LeetCode之String题目汇总
Count and SayThe 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原创 2015-12-27 16:28:05 · 783 阅读 · 0 评论 -
LeetCode之Math题目汇总
Add BinaryGiven two binary strings, return their sum (also a binary string).For example, a = "11" b = "1" Return "100". public ListNode addTwoNumbers(ListNode l1, ListNode l2) { if (l1 ==原创 2015-12-27 13:04:31 · 1037 阅读 · 0 评论 -
LeetCode之Linked List题目汇总
Add Two NumbersYou 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 digit. Add the two numbers and retur原创 2015-12-27 10:59:37 · 815 阅读 · 0 评论 -
LeetCode之Hash Table题目汇总
我的博客:http://blog.youkuaiyun.com/yano_nankai LeetCode题解:https://github.com/LjyYano/LeetCodeGroup AnagramsGiven an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "原创 2015-12-24 11:15:16 · 3619 阅读 · 0 评论 -
LeetCode 049 Group Anagrams
题目描述Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note:For the retu原创 2015-12-24 10:14:52 · 555 阅读 · 0 评论 -
LeetCode之Array题目汇总
Two SumGiven 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 numbers such that they add up to the target, w原创 2015-12-23 19:28:39 · 4564 阅读 · 0 评论 -
LeetCode 033 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 return its i原创 2015-12-23 16:58:30 · 664 阅读 · 0 评论 -
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], therefor原创 2015-12-14 16:58:49 · 2477 阅读 · 3 评论 -
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原创 2015-12-14 15:36:33 · 906 阅读 · 1 评论 -
LeetCode 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 to原创 2015-12-14 15:13:35 · 2866 阅读 · 0 评论 -
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原创 2015-12-14 10:31:24 · 2398 阅读 · 0 评论 -
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.Example原创 2015-12-14 10:27:29 · 636 阅读 · 0 评论 -
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原创 2015-12-14 10:15:09 · 1691 阅读 · 0 评论 -
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 re原创 2015-12-14 10:00:47 · 2812 阅读 · 0 评论 -
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 f原创 2015-12-14 09:42:07 · 603 阅读 · 0 评论 -
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, re原创 2015-12-14 09:38:22 · 644 阅读 · 0 评论 -
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原创 2015-12-14 09:31:50 · 389 阅读 · 0 评论 -
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?Hint:Expected runtime complexity is in O(log n) and the input is sorted.分析二分查找代码原创 2015-12-14 09:27:27 · 573 阅读 · 0 评论 -
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 s原创 2015-12-14 09:23:17 · 2529 阅读 · 0 评论 -
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 Three H原创 2015-12-12 11:26:06 · 601 阅读 · 0 评论 -
LeetCode 268 Missing Number
题目描述Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in原创 2015-12-12 11:22:46 · 3587 阅读 · 1 评论 -
LeetCode 264 Ugly Number II
题目描述Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10原创 2015-12-12 11:17:24 · 590 阅读 · 1 评论 -
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 i原创 2015-12-12 11:04:02 · 466 阅读 · 0 评论 -
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 =原创 2015-12-12 11:00:13 · 576 阅读 · 0 评论 -
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 digi原创 2015-12-12 10:46:14 · 473 阅读 · 0 评论 -
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"]Credits: Special thanks to原创 2015-12-12 10:40:43 · 1581 阅读 · 0 评论