![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetCode
编码886
这个作者很懒,什么都没留下…
展开
-
leetCode 29.Divide Two Integers (两整数相除) 解题思路和方法
Divide Two Integers Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路:这个题算法上不是很难,但是通过率相当低,只有15%,果然,自己在写完之后,各种出错,而且错误不是算法上原创 2015-07-07 23:26:53 · 1019 阅读 · 0 评论 -
leetCode 32.Longest Valid Parentheses (有效的最大括号) 解题思路和方法
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 par原创 2015-07-08 16:26:06 · 831 阅读 · 0 评论 -
leetCode 1. Two Sum 解题思路和方法
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原创 2015-06-30 16:20:35 · 1005 阅读 · 0 评论 -
leetCode 34.Search for a Range (搜索范围) 解题思路和方法
Search for a Range Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If原创 2015-07-09 12:58:59 · 714 阅读 · 0 评论 -
leetCode 30.Substring with Concatenation of All Words (words中所有子串相连) 解题思路和方法
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 concate原创 2015-07-08 11:11:35 · 779 阅读 · 0 评论 -
leetCode 35.Search Insert Position (搜索插入位置) 解题思路和方法
Search Insert PositionGiven 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原创 2015-07-09 16:24:25 · 1598 阅读 · 1 评论 -
leetCode 39.Combination Sum(组合总和) 解题思路和方法
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from原创 2015-07-09 22:33:11 · 4735 阅读 · 1 评论 -
leetCode 36.Valid Sudoku(有效的数独) 解题思路和方法
Valid SudokuDetermine 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 parti原创 2015-07-09 17:33:47 · 2682 阅读 · 0 评论 -
leetCode 38.Count and Say (计数和发言) 解题思路和方法
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 i原创 2015-07-09 20:40:16 · 13395 阅读 · 4 评论 -
leetCode 40.Combination Sum II(组合总和II) 解题思路和方法
Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used原创 2015-07-09 23:11:43 · 1513 阅读 · 0 评论 -
leetCode 41.First Missing Positive (第一个丢失的正数) 解题思路和方法
First Missing Positive Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in原创 2015-07-10 10:25:58 · 2581 阅读 · 1 评论 -
leetCode 5.Longest Palindromic Substring 解题思路与方法
问题:Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic原创 2015-07-04 13:25:49 · 648 阅读 · 0 评论 -
leetCode 42.Trapping Rain Water(凹槽的雨水) 解题思路和方法
Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0原创 2015-07-11 14:04:18 · 1336 阅读 · 0 评论 -
leetCode 43.Multiply Strings(高精度整数相乘) 解题思路和方法
Multiply StringsGiven two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.思路:此题因为没有负数,所以没原创 2015-07-11 17:32:49 · 856 阅读 · 0 评论 -
leetCode 3. Longest Substring Without Repeating Characters 解法与思路
问题:Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating let原创 2015-07-01 11:40:44 · 620 阅读 · 0 评论 -
leetCode 7. Reverse Integer (数字反转) 解题思路与方法
问题:Reverse Integer Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321本题需要注意的地方在于数字反转后有可能溢出,所以需要判断时候溢出,溢出时返回0。本题用了两种方法实现,第一种是反转字符串,第二种是直接循环读出末原创 2015-07-04 20:03:10 · 1053 阅读 · 0 评论 -
leetCode 4. Median of Two Sorted Arrays 解题思路和方法
问题:Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2of size m and n respectively. Find the median of the two sorted arrays. Theoverall run time complexity should be O(log (m+n原创 2015-07-03 20:06:20 · 714 阅读 · 0 评论 -
leetCode 8. String to Integer (atoi) (字符串转整形) 解题思路和方法
问题:String to Integer (atoi) 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 yoursel原创 2015-07-04 21:59:06 · 621 阅读 · 0 评论 -
leetCode 6. ZigZag Conversion(Z形变换) 解题思路及方法
问题:ZigZag ConversionThe 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)原创 2015-07-04 15:28:02 · 882 阅读 · 0 评论 -
leetCode 45.Jump Game II (跳跃游戏) 解题思路和方法
Jump Game IIGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position原创 2015-07-12 12:35:47 · 3312 阅读 · 0 评论 -
leetCode 46.Permutations(排列组合) 解题思路和方法
PermutationsGiven a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].原创 2015-07-12 19:12:29 · 868 阅读 · 0 评论 -
leetCode 90.Subsets II(子集II) 解题思路和方法
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain du原创 2015-07-25 09:54:00 · 2005 阅读 · 0 评论 -
leetcode 10.Regular Expression Matching(正则表达式匹配) 解题思路和方法
Regular Expression MatchingImplement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The match原创 2015-07-05 16:07:22 · 1292 阅读 · 0 评论 -
leetCode 11.Container With Most Water (数轴上容器) 解题思路和方法
Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at原创 2015-07-05 17:31:36 · 449 阅读 · 0 评论 -
leetCode 9.Palindrome Number (回文数字) 解题思路和方法
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 convert原创 2015-07-05 13:58:10 · 553 阅读 · 0 评论 -
leetCode 12.Integer to Roman (整数转罗马数字) 解题思路和方法
Integer to Roman Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题目比价简单,也好理解。不过罗马数字中最主要的是4的表示,代码如下:public class Solution {原创 2015-07-05 18:50:45 · 489 阅读 · 0 评论 -
leetCode 2 Add Two Numbers
问题:Add Two NumbersYou 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 t原创 2015-06-30 22:35:34 · 433 阅读 · 0 评论 -
leetCode 44.Wildcard Matching (通配符匹配) 解题思路和方法
Wildcard Matching'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).Th原创 2015-07-11 21:09:39 · 1334 阅读 · 0 评论 -
leetCode 93.Restore IP Addresses (恢复IP地址) 解题思路和方法
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2015-07-27 09:52:23 · 5640 阅读 · 1 评论 -
leetCode 13.Roman to Integer (罗马数字转整形) 解题思路和方法
Roman to Integer Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:开始解此题的时候,立马想到上题的反转公式。话不多说,上代码。具体思路代码注释。public class Solution原创 2015-07-05 20:54:02 · 693 阅读 · 0 评论 -
leetCode 14.Longest Common Prefix(最长公共前缀) 解题思路和方法
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.题目比较简单,没什么好说的,直接上代码。public class Solution { public String longestCommonPrefix(Strin原创 2015-07-05 21:30:40 · 560 阅读 · 0 评论 -
leetCode 47.Permutations II (排列组合II) 解题思路和方法
Permutations II Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,原创 2015-07-13 13:09:08 · 679 阅读 · 0 评论 -
leetCode 49.Anagrams (回文构词法) 解题思路和方法
Anagrams Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:这题要是解,必须知道什么是回文构词法。所谓回文构词法就是把一个单词的顺序调整,形成新的单词,如”eat“,"tea"就是回原创 2015-07-13 13:15:19 · 1166 阅读 · 0 评论 -
leetCode 50.Pow(x, n) (x的n次方) 解题思路和方法
Pow(x, n) Implement pow(x, n).思路:题目不算难,但是需要考虑的情况比较多。具体代码如下:public class Solution { public double myPow(double x, int n) { boolean isMin0 = true;//结果负号 if(x > 0 || (n&1) ==原创 2015-07-13 13:21:41 · 795 阅读 · 0 评论 -
leetCode 51.N-Queens (n皇后问题) 解题思路和方法
N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-quee原创 2015-07-13 13:23:15 · 1883 阅读 · 0 评论 -
leetCode 52.N-Queens II (n皇后问题II) 解题思路和方法
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路:解决了上题,这题也就迎刃而解,或者说这题要不上题还要简单一些。具体代码如下:pub原创 2015-07-13 14:08:30 · 2659 阅读 · 0 评论 -
leetCode 48.Rotate Image (旋转图像) 解题思路和方法
Rotate ImageYou 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?思路:其实就是旋转数组,没有什么难度,代码如下:public原创 2015-07-13 13:13:04 · 1308 阅读 · 0 评论 -
leetCode 16.3Sum Closest (离给定值最近的三数之和) 解题思路和方法
3Sum Closest Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input wou原创 2015-07-06 11:34:36 · 495 阅读 · 0 评论 -
leetCode 18.4Sum (4数字和) 解题思路和方法
4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elemen原创 2015-07-06 16:00:39 · 577 阅读 · 0 评论 -
leetCode 22.Generate Parentheses (生成括号) 解题思路和方法
Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())"原创 2015-07-06 22:11:08 · 1746 阅读 · 0 评论