![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
客船
这个作者很懒,什么都没留下…
展开
-
leetcode之Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[lef原创 2015-12-03 21:12:47 · 1433 阅读 · 0 评论 -
Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me原创 2015-10-08 23:00:11 · 862 阅读 · 0 评论 -
Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits: Special thanks to @mithmatt for adding this problem and creating all test cases.思路:采用筛选法,先把N个自然数按次序排列起来。1不是质数,原创 2015-10-08 22:45:01 · 873 阅读 · 0 评论 -
Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another chara原创 2015-10-08 19:15:00 · 884 阅读 · 0 评论 -
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 is原创 2015-10-08 12:26:37 · 983 阅读 · 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 any原创 2015-11-06 20:17:29 · 281 阅读 · 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 bot原创 2015-11-06 20:04:32 · 296 阅读 · 0 评论 -
Count and Say
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 “one 2, the原创 2015-09-16 20:27:31 · 846 阅读 · 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 houses原创 2015-11-05 20:24:01 · 1340 阅读 · 0 评论 -
leetcode之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. Design an algorithm to find the maximum profit. Note: You may not engage in multiple transactions at the same原创 2015-11-04 21:54:53 · 485 阅读 · 0 评论 -
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 re原创 2015-09-16 14:44:58 · 815 阅读 · 0 评论 -
Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should trunca原创 2015-09-16 18:58:25 · 849 阅读 · 0 评论 -
Compare Version Numbers
Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and conta原创 2015-09-15 21:30:45 · 485 阅读 · 0 评论 -
Reverse Words in a String
Given an input string, reverse the string word by word.For example, Given s = “the sky is blue”, return “blue is sky the”.Update (2015-02-12): For C programmers: Try to solve it in-place in O(1) spa原创 2015-09-30 16:41:50 · 603 阅读 · 0 评论 -
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 “BANC”.Note:原创 2015-09-29 15:46:14 · 295 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wit原创 2015-09-30 12:51:19 · 367 阅读 · 0 评论 -
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 palin原创 2015-09-28 22:31:19 · 545 阅读 · 0 评论 -
Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Examples: pattern = “abba”, str = “dog cat cat dog” should return true. pattern = “abba”, str = “dog cat cat fish” should return原创 2015-10-08 18:56:05 · 1098 阅读 · 0 评论 -
Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 思路:哈希表问题,原创 2015-10-08 19:24:05 · 809 阅读 · 0 评论 -
leetcode之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, return原创 2015-12-03 22:29:19 · 399 阅读 · 0 评论 -
leetcode之Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red borde原创 2015-12-03 08:58:25 · 349 阅读 · 0 评论 -
leetcode之Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRange(0, 5原创 2015-12-02 08:31:58 · 322 阅读 · 0 评论 -
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-12-01 21:36:11 · 300 阅读 · 0 评论 -
leetcode之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 ugly原创 2015-12-11 16:56:18 · 368 阅读 · 0 评论 -
LeetCode之Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?思路:先对matrix进行转置,然后reverse每一行中的数据,举个例子 1 2 3……………. 7 4 1……………原创 2015-10-14 22:58:28 · 853 阅读 · 0 评论 -
Rotate Array
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 you can, ther原创 2015-10-13 19:38:58 · 913 阅读 · 0 评论 -
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 Hu原创 2015-09-25 16:11:09 · 806 阅读 · 0 评论 -
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 line原创 2015-10-11 22:10:24 · 941 阅读 · 0 评论 -
LeetCode之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.Here原创 2015-10-24 21:32:08 · 372 阅读 · 0 评论 -
LeetCode之Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x. 题目解析:求整数x的平方根 思路:因为题目只是要求求整数的平方根,且返回的结果也是整数,因此该问题可以看做是一个搜索问题,搜索的范围为[0,x/2+1](sqrt(x)<=x/2+1可推导出(x−1)2>=0sqrt(x)<=x/2+1可推导出(x-1)^2>=0原创 2015-10-24 21:23:26 · 418 阅读 · 0 评论 -
leetcode之Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2], [3,4], [6,5,原创 2015-11-09 13:21:43 · 343 阅读 · 0 评论 -
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 digit, r原创 2015-10-09 23:09:18 · 853 阅读 · 0 评论 -
Same Tree
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. 思路:遍历看输出结果是否相同即可,原创 2015-10-09 23:45:19 · 904 阅读 · 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] has the原创 2015-10-23 17:11:55 · 522 阅读 · 0 评论 -
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 / 3 return [1,3,2].Note: Recursive solution is trivial,原创 2015-10-09 16:29:49 · 849 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which has原创 2015-09-28 19:17:04 · 821 阅读 · 0 评论 -
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 思路:看到这到题第一想法是用dividend每次减一个divisor,直到dividend小于divisor,减的次数即为所求的解,显然当dividend比较大而divisor比原创 2015-09-07 16:02:32 · 297 阅读 · 0 评论 -
Remove Nth Node From End of List
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 linked list be原创 2015-08-28 22:00:16 · 211 阅读 · 0 评论 -
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 linke原创 2015-08-14 00:12:22 · 335 阅读 · 0 评论 -
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 valid but “原创 2015-08-28 22:53:02 · 225 阅读 · 0 评论