
LeetCode easy
文章平均质量分 62
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
Factorial Trailing Zeroes (Java)
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.题目大意是说找出n!算出的数末尾有多少个零。找末尾零就相当于找从1到n中有多少个2和5,如果用for(i = 1; i原创 2015-01-09 11:31:25 · 372 阅读 · 0 评论 -
Climbing Stairs (Java)
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Sourcepublic class Solut原创 2014-12-26 16:01:47 · 535 阅读 · 0 评论 -
Minimum Depth of Binary Tree (Java)
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 leaf node.Sourcepublic int minDepth(Tree原创 2014-12-24 09:54:03 · 324 阅读 · 0 评论 -
Merge Two Sorted Lists (Java)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Source原创 2014-10-29 20:54:39 · 429 阅读 · 0 评论 -
Length of Last Word (Java)
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-10-28 21:52:20 · 405 阅读 · 0 评论 -
Remove Nth Node From End of List (Java)
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-10-27 21:36:56 · 317 阅读 · 0 评论 -
Longest Common Prefix (Java)
Write a function to find the longest common prefix string amongst an array of strings.Source原创 2014-10-16 12:36:01 · 514 阅读 · 0 评论 -
String to Integer (atoi) (Java)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2014-10-15 21:27:12 · 725 阅读 · 0 评论 -
Reverse Integer (Java)
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Source原创 2014-10-15 16:30:42 · 445 阅读 · 0 评论 -
Excel Sheet Column Number (Java)
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2014-12-31 21:01:18 · 588 阅读 · 0 评论 -
Remove Duplicates from Sorted Array (Java)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-10-28 10:34:37 · 464 阅读 · 0 评论 -
Binary Tree Level Order Traversal (Java)
Given 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}, 3 / \ 9 20原创 2014-12-24 20:29:01 · 354 阅读 · 0 评论 -
Binary Tree Level Order Traversal II (Java)
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-12-24 20:41:37 · 390 阅读 · 0 评论 -
Rotate Array (Java)
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo原创 2015-02-27 19:35:34 · 521 阅读 · 0 评论 -
Remove Element (Java)
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 matter what you leave beyond the new length.S原创 2014-10-28 10:20:58 · 417 阅读 · 0 评论 -
Valid Sudoku (Java)
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 the character '.'.A partially fille原创 2014-10-28 15:34:10 · 1304 阅读 · 0 评论 -
Plus One (Java)
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 the head of the list.Sourcepublic cla原创 2014-12-26 11:27:17 · 463 阅读 · 0 评论 -
Majority Element (Java)
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2014-12-22 14:25:20 · 953 阅读 · 0 评论 -
Palindrome Number (Java)
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-10-16 10:28:16 · 320 阅读 · 0 评论 -
Roman to Integer (Java)
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.原创 2014-10-16 19:56:51 · 512 阅读 · 0 评论 -
Valid Parentheses (Java)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-10-28 10:07:47 · 496 阅读 · 0 评论 -
Add Binary (Java)
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Sourcepublic class Solution { public String addBinary(String a, St原创 2014-12-26 10:41:48 · 474 阅读 · 0 评论 -
Merge Sorted Array (Java)
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements f原创 2014-12-25 17:47:59 · 391 阅读 · 0 评论 -
Maximum Depth of Binary Tree (Java)
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 leaf node.Sourcepublic int maxDepth(原创 2014-12-24 15:35:26 · 352 阅读 · 0 评论 -
Compare Version Numbers (Java)
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2014-12-24 15:23:07 · 595 阅读 · 0 评论 -
ZigZag Conversion (Java)
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 for better legibility)P A H NA P L S I原创 2014-10-15 15:46:13 · 524 阅读 · 0 评论 -
Remove Duplicates from Sorted List (Java)
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Source/** * Defini原创 2014-12-25 18:41:07 · 354 阅读 · 0 评论 -
Path Sum (Java)
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.For example:Given the below binary tree and原创 2014-12-23 22:02:18 · 326 阅读 · 0 评论 -
Pascal's Triangle (Java)
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Sourcepu原创 2014-12-23 17:05:10 · 741 阅读 · 0 评论 -
Intersection of Two Linked Lists (Java)
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: a1 → a2 ↘原创 2014-12-22 16:43:13 · 382 阅读 · 0 评论 -
Balanced Binary Tree (Java)
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 of the two subtrees of every node never diffe原创 2014-12-21 13:22:59 · 538 阅读 · 0 评论 -
Same Tree (Java)
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 and the nodes have the same value.Sour原创 2014-12-24 22:09:19 · 310 阅读 · 0 评论 -
Symmetric Tree (Java)
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 / \ 2 2 / \ / \3 4 4 3But the f原创 2014-12-24 22:01:14 · 334 阅读 · 0 评论 -
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 -> Z 27 -> AA 28 -> AB S原创 2014-12-21 21:38:28 · 370 阅读 · 0 评论 -
Valid Palindrome (Java)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-12-23 10:31:29 · 337 阅读 · 0 评论 -
Min Stack (Java)
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 the element on top of the stack.top() -- Get原创 2014-12-22 21:10:37 · 347 阅读 · 0 评论 -
Count and Say (Java)
The 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 as原创 2014-10-28 19:34:09 · 466 阅读 · 0 评论 -
Implement strStr() (Java)
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.注意 " "原创 2014-10-28 13:12:33 · 346 阅读 · 0 评论 -
Pascal's Triangle II (Java)
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?上一行从原创 2014-12-23 20:54:29 · 403 阅读 · 0 评论