
leetcode-easy
石前有座桥
学生
展开
-
1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam原创 2017-12-25 14:32:23 · 145 阅读 · 0 评论 -
7.Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dea...原创 2019-04-04 17:18:00 · 109 阅读 · 0 评论 -
9. Palindrome Number
Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: falseExpl...原创 2019-04-07 17:13:22 · 85 阅读 · 0 评论 -
13. Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-07 17:48:20 · 76 阅读 · 0 评论 -
27. Remove Element
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input array...原创 2019-04-11 14:33:35 · 79 阅读 · 0 评论 -
28. Implement strStr()
ImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example...原创 2019-04-11 14:41:14 · 67 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".Example 1:Input: ["flower","flow","flight"]Output:...原创 2019-04-08 11:22:48 · 81 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-04-08 17:48:05 · 77 阅读 · 0 评论 -
35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array....原创 2019-04-12 09:12:29 · 210 阅读 · 0 评论 -
21. Merge Two Sorted Lists
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.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2019-04-09 11:17:17 · 100 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bymodifyi...原创 2019-04-09 11:44:44 · 85 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1-...原创 2019-04-16 09:32:58 · 97 阅读 · 0 评论 -
53. Maximum Subarray
Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...原创 2019-04-13 10:03:20 · 115 阅读 · 0 评论 -
88. Merge Sorted Array
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume that...原创 2019-04-16 15:11:19 · 107 阅读 · 0 评论 -
58. Length of Last Word
Given a stringsconsists 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 defin...原创 2019-04-13 12:58:48 · 128 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...原创 2019-04-21 17:28:06 · 91 阅读 · 0 评论 -
66. Plus One
Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element...原创 2019-04-14 09:27:16 · 136 阅读 · 0 评论 -
100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example ...原创 2019-04-17 09:05:23 · 89 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).The input strings are bothnon-emptyand contains only characters1or0.Example 1:Input: a = "11", b = "1"Output: "100"Exam...原创 2019-04-14 14:13:51 · 107 阅读 · 0 评论 -
125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.Examp...原创 2019-04-26 10:31:07 · 89 阅读 · 0 评论 -
136. Single Number
Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...原创 2019-04-26 10:48:03 · 138 阅读 · 0 评论 -
101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1 / \ 2 2 / \ / \3 4 4 3...原创 2019-04-17 16:03:08 · 85 阅读 · 0 评论 -
110. Balanced Binary Tree
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 ofeverynode never diffe...原创 2019-04-22 16:43:19 · 87 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
111.Minimum Depth of Binary TreeEasy679361FavoriteShareGiven 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 ...原创 2019-04-22 16:51:38 · 108 阅读 · 0 评论 -
69. Sqrt(x)
Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer.Since the return typeis an integer, the decimal digits are truncated and only...原创 2019-04-15 10:50:40 · 101 阅读 · 0 评论 -
70. Climbing Stairs
You are climbing a stair case. It takesnsteps 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?Note:Givennwill be a positive...原创 2019-04-15 14:28:59 · 151 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree
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.Note:A leaf is a node with no childre...原创 2019-04-18 09:23:17 · 123 阅读 · 0 评论 -
141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where tail co...转载 2019-04-27 09:50:11 · 106 阅读 · 0 评论 -
112. Path Sum
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.Note:A leaf is a node with no children.Example:...原创 2019-04-23 09:24:26 · 85 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
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 example:Given binary tree[3,9,20,null,null,15,7...原创 2019-04-18 14:17:06 · 91 阅读 · 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 the element on top of the stack. top() -- Ge...转载 2019-04-27 14:34:50 · 83 阅读 · 0 评论 -
118. Pascal's Triangle
Given a non-negative integernumRows, generate the firstnumRowsof Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:...原创 2019-04-23 13:55:06 · 144 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
Given an integern, return the number of trailing zeroes inn!.Example 1:Input: 3Output: 0Explanation:3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation:5! = 120, one trai...转载 2019-05-02 18:42:00 · 145 阅读 · 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:begin to intersect at node c1.Example 1:Input: ...原创 2019-04-28 14:41:52 · 159 阅读 · 0 评论 -
189. Rotate Array
Given an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1...原创 2019-05-03 13:52:43 · 172 阅读 · 0 评论 -
119. Pascal's Triangle II
Given a non-negativeindexkwherek≤33, return thekthindex row of the Pascal's triangle.Note that the row index starts from0.In Pascal's triangle, each number is the sum of the two numbers ...原创 2019-04-24 10:11:52 · 100 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.Example 1:Input: 00000010100101000001111010011100Output: 00111001011110000010100101000000Explanation: The input binary string 000000101001010...原创 2019-05-04 10:38:51 · 87 阅读 · 0 评论 -
191. Number of 1 Bits
Write a function that takes an unsigned integer and returnthe number of '1'bits it has (also known as theHamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanat...原创 2019-05-04 10:44:03 · 93 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2019-04-24 13:22:48 · 100 阅读 · 0 评论 -
198. House Robber
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 you from robbing each of them is that adjacent house...原创 2019-05-04 19:16:57 · 108 阅读 · 0 评论