![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 67
do_smile
这个作者很懒,什么都没留下…
展开
-
LeetCode | 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]]//杨辉三角:每一行,头尾为1,中间元素为其上一行两肩位原创 2015-06-15 11:06:31 · 261 阅读 · 0 评论 -
LeetCode | 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 retur原创 2015-06-24 19:46:41 · 295 阅读 · 0 评论 -
LeetCode | Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.要求不使用乘法、除法或模运算实现: dividend/divisor,也就是只能用加、减或位运算。int的取值范围[-2147483648, 2147483647],即原创 2015-06-22 14:43:49 · 343 阅读 · 0 评论 -
LeetCode | Pow(x, n)
Implement pow(x, n).//tag提示用binary search,主要就是确定有多少个x来相乘。//思想是对n进行二分。注意下n可能为负数public class Solution { public double myPow(double x, int n) { if(n == 0) return 1; dou原创 2015-06-21 14:52:34 · 291 阅读 · 0 评论 -
LeetCode | Sqrt (x)
Implement int sqrt(int x).Compute and return the square root of x.//tag提示用binary search。要求的返回结果是int,不是实际的平方跟,用二分法找到最合适的int就行public class Solution { public int mySqrt(int x) { if(x <原创 2015-06-21 11:35:53 · 249 阅读 · 0 评论 -
LeetCode | 3 Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2015-06-18 18:39:15 · 260 阅读 · 0 评论 -
LeetCode | Pascal's Triangle II
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?按昨天的思路,不考虑空间复杂度的原创 2015-06-16 15:12:53 · 236 阅读 · 0 评论 -
LeetCode | 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原创 2015-05-04 11:10:21 · 215 阅读 · 0 评论 -
LeetCode | Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-05-03 11:33:01 · 237 阅读 · 0 评论 -
LeetCode | Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2015-05-10 15:32:40 · 292 阅读 · 0 评论 -
LeetCode | Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2015-04-27 19:41:00 · 340 阅读 · 0 评论 -
LeetCode | Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example, Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-04-26 13:42:21 · 304 阅读 · 0 评论 -
LeetCode | Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2015-04-23 15:42:01 · 269 阅读 · 0 评论 -
LeetCode | Majority Element
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原创 2015-04-20 15:44:06 · 302 阅读 · 0 评论 -
LeetCode | Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2015-06-25 15:38:33 · 309 阅读 · 0 评论 -
LeetCode | Find Minimum 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).Find the minimum element.You may assume no duplicate exists in原创 2015-06-27 10:59:03 · 237 阅读 · 0 评论 -
LeetCode | Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot u原创 2015-06-27 11:19:12 · 316 阅读 · 0 评论 -
LeetCode | 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 Howe原创 2015-06-13 15:12:56 · 302 阅读 · 0 评论 -
LeetCode | Plus One
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.//思想类似于前两天的add binary与原创 2015-06-12 10:22:58 · 224 阅读 · 0 评论 -
LeetCode | Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.//要求找到字符串数组中所有string的最长公共前缀//用brute force的方法,取第一个字符串的每一个字符来遍历数组public class Solution { public String lo原创 2015-06-11 19:54:47 · 285 阅读 · 0 评论 -
LeetCode | Add Two Numbers
You 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 return it as a link原创 2015-06-10 18:39:26 · 327 阅读 · 0 评论 -
LeetCode | Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-linked原创 2015-07-01 14:38:40 · 311 阅读 · 0 评论 -
LeetCode | Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2015-06-29 20:44:11 · 307 阅读 · 0 评论 -
LeetCode | Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = "11" b = "1" Return "100".//思想是从后向前,从低位开始逐位相加,结果放到一个StringBuilder中,并用carry来表示是否有进位//某个字符串用光之后,另一个字符串的剩余部分加上car原创 2015-06-09 13:03:37 · 293 阅读 · 0 评论 -
LeetCode | Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an原创 2015-06-28 20:18:31 · 552 阅读 · 0 评论 -
LeetCode | Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-06-30 11:25:55 · 297 阅读 · 0 评论 -
LeetCode | Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at most原创 2015-06-28 09:53:22 · 444 阅读 · 0 评论 -
LeetCode | Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2015-06-28 09:28:51 · 452 阅读 · 0 评论 -
LeetCode | 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原创 2015-06-07 10:38:29 · 278 阅读 · 0 评论 -
LeetCode | Two Sum
Given 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, whe原创 2015-06-17 16:29:47 · 233 阅读 · 0 评论 -
LeetCode | 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] ha原创 2015-04-13 14:04:39 · 315 阅读 · 0 评论 -
LeetCode | 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?tag: dynamicprogrammingp原创 2015-04-22 12:55:47 · 288 阅读 · 0 评论 -
LeetCode | Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for y原创 2014-12-27 15:41:59 · 321 阅读 · 0 评论 -
LeetCode | 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.原创 2014-11-02 09:36:27 · 258 阅读 · 0 评论 -
LeetCode | 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 in place with原创 2014-11-01 15:50:54 · 280 阅读 · 0 评论 -
LeetCode | Merge Sorted Array
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 from原创 2014-10-29 16:40:31 · 336 阅读 · 0 评论 -
LeetCode | Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].原创 2014-11-14 15:30:14 · 306 阅读 · 0 评论 -
LeetCode | Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3]. Note: Recursive solutio原创 2014-11-14 15:07:17 · 270 阅读 · 0 评论 -
LeetCode | Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is t原创 2014-11-14 15:22:12 · 276 阅读 · 0 评论 -
LeetCode | 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.原创 2014-10-29 11:41:43 · 322 阅读 · 0 评论