leetcode
chineseqsc
这个作者很懒,什么都没留下…
展开
-
26.Remove Duplicates from Sorted Array
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 by modifying th原创 2018-01-30 22:18:29 · 97 阅读 · 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->1->原创 2018-01-30 22:15:41 · 98 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-plac原创 2018-01-31 17:32:14 · 86 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example原创 2018-01-31 20:27:42 · 78 阅读 · 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.原创 2018-01-31 21:23:54 · 90 阅读 · 0 评论 -
38. Count and Say (计数与报数)
The count-and-say sequence is the sequence of integers with the first five terms as following: 1 11 21 1211 111221 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21原创 2018-02-01 10:49:08 · 572 阅读 · 0 评论 -
53. Maximum Subarray
Find the contiguous(邻近的) subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1]原创 2018-02-01 12:26:32 · 108 阅读 · 0 评论 -
58. Length of Last Word
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 defin原创 2018-02-01 16:34:36 · 86 阅读 · 0 评论 -
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原创 2018-01-26 19:59:52 · 109 阅读 · 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:原创 2018-01-26 20:46:26 · 106 阅读 · 0 评论 -
66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. The digits a原创 2018-02-02 21:58:05 · 82 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.1。因为字符串的顺序是从高到低进行存储的,不方便对齐进行加法,所以我们将a和b中较短的字符串前面添加一些0来使得他们的长度变为一致。 2.然后从a和b的最低位开始逐位原创 2018-02-02 22:51:11 · 93 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer. Example 1: Input: 4 Output: 2Example 2: Input: 8 Output: 2 Expl原创 2018-02-03 11:10:09 · 132 阅读 · 0 评论 -
9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2018-01-27 21:48:56 · 114 阅读 · 0 评论 -
13. Roman to Integer(运行时间有待改进)
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.罗马数字是最古老的数字表示方式,比阿拉伯数组早2000多年,起源于罗马罗马数字有如下符号:基本字符IVXLCD转载 2018-01-27 23:03:42 · 120 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
Say 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 sell one share of the stock), d...原创 2018-02-09 11:17:32 · 106 阅读 · 0 评论 -
70. Climbing Stairs
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?Note: Given n will be a positive原创 2018-02-04 15:42:15 · 90 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
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. /** * Definition for原创 2018-02-04 16:40:01 · 89 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings."abcdefg""abcdefghijk""abcdfghijk""abcef"上面的字符串数组的最长公共前缀就是"abc"。class Solution {public: string longes原创 2018-01-28 22:03:35 · 89 阅读 · 0 评论 -
20. Valid Parentheses
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原创 2018-01-28 22:49:28 · 80 阅读 · 0 评论 -
88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additio原创 2018-02-04 22:29:31 · 77 阅读 · 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.方法一:递归原创 2018-02-05 11:08:53 · 84 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one ...原创 2018-02-09 15:44:28 · 86 阅读 · 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原创 2018-02-05 20:10:52 · 78 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011...原创 2018-02-26 10:40:40 · 142 阅读 · 0 评论 -
191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 0000000000...原创 2018-02-26 11:06:32 · 109 阅读 · 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.For example: Given binary tree [3,9,2原创 2018-02-06 09:44:07 · 89 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
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,null,null,15,原创 2018-02-06 15:17:57 · 69 阅读 · 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...原创 2018-02-26 20:12:21 · 94 阅读 · 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(Binary Sort Tree).For this problem, a height-balanced binary tree(平衡二叉树) is defined as a binary tree原创 2018-02-07 11:34:44 · 116 阅读 · 0 评论 -
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 ...原创 2018-03-06 19:39:27 · 98 阅读 · 0 评论 -
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, replace the number by the sum of the squares o...原创 2018-02-27 15:44:07 · 92 阅读 · 0 评论 -
125. Valid Palindrome
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 pa...原创 2018-02-13 23:08:07 · 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 of every node never di原创 2018-02-07 17:57:46 · 105 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
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./** * Definition for a binary tree no原创 2018-02-07 20:30:05 · 105 阅读 · 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.For example: Given the below binary tree and sum原创 2018-02-07 21:03:09 · 83 阅读 · 0 评论 -
203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 删除指定值的所有...原创 2018-02-27 16:22:52 · 81 阅读 · 0 评论 -
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"]递归:/...原创 2018-03-07 16:01:33 · 70 阅读 · 0 评论 -
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 dig...原创 2018-03-07 16:40:04 · 80 阅读 · 0 评论 -
118. Pascal's Triangle
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] ]discussclass Solution ...原创 2018-02-08 17:19:28 · 93 阅读 · 0 评论