LeetCode
文章平均质量分 70
prince谢晓峰
人工智能搬砖工。
展开
-
LeetCode 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 us...原创 2018-03-15 15:20:07 · 170 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers(单链表求和)
题目描述: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers...原创 2018-03-15 15:59:48 · 469 阅读 · 0 评论 -
LeetCode 3. Longest Substring Without Repeating Characters(最长不重复连续子串)
题目描述: Given a string, find the length of the longest substring without repeating characters.例子:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with t...原创 2018-03-15 16:33:44 · 120 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays(两个有序数组的中位数)
题目描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).例子:nums1 = [1...原创 2018-03-15 19:51:26 · 107 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring(最长回文连续子串)
题目描述: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.例子:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Input: ...原创 2018-03-15 20:11:46 · 163 阅读 · 0 评论 -
LeetCode 6. ZigZag Conversion(之字形排列)
题目描述: The 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)例子:P A H NA ...原创 2018-03-16 16:57:09 · 635 阅读 · 0 评论 -
LeetCode 7. Reverse Integer(整数反转)
题目描述: Given a 32-bit signed integer, reverse digits of an integer.例一:Input: 123Output: 321例二:Input: -123Output: -321例三:Input: 120Output: 21注意: Assume we are dealing with an environment which ...原创 2018-03-16 17:44:31 · 131 阅读 · 0 评论 -
LeetCode 8. String to Integer (atoi)(字符串转整数)
题目描述: Implement atoi to convert a string to an integer. 提示:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible in...原创 2018-03-16 18:20:35 · 153 阅读 · 0 评论 -
LeetCode 9. Palindrome Number(回文整数)
题目描述: Determine whether an integer is a palindrome. Do this without extra space.分析: 题意:判断一个整数是否是一个回文数。 思路:我们先看几种特殊情况:①负数不是回文数(如-12);②个位数是0的非零数不是回文数(如120),显然0是回文数;③一般情况,我们可以计算获得一个数的后半段的逆序,并和它的...原创 2018-03-16 19:13:56 · 185 阅读 · 0 评论 -
LeetCode 10. Regular Expression Matching(正则表达式匹配)
题目描述: Implement regular expression matching with support for '.' and '*'.例子:'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entir...原创 2018-03-16 19:57:04 · 116 阅读 · 0 评论 -
LeetCode 11. 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 (i, ai) and (i, 0). ...原创 2018-03-17 14:08:58 · 121 阅读 · 0 评论 -
LeetCode 12. Integer to Roman(罗马字符转阿拉伯数字)
题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.分析: 题意:给定一个阿拉伯数字(范围是1~3999),把它转化为对应的罗马数字。 思路:这是一道数学题,我们需要知道阿拉伯数字和罗马数字的转化关系:...原创 2018-03-17 14:26:20 · 155 阅读 · 0 评论 -
LeetCode 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.分析: 题意:给定一个罗马数字(范围是1~3999),把它转化为对应的阿拉伯数字。 思路:这是一道数学题,跟LeetCode 12是互逆的关系。我们需...原创 2018-03-17 14:35:31 · 126 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix(最长公共前缀)
题目描述: Write a function to find the longest common prefix string amongst an array of strings.分析: 题意:给定一些字符串,求它们的最长公共前缀。 思路:先求得所有字符串的最短长度min_length,那么它将是公共前缀可能的最长长度,我们分别获得min_length→1长度的某个字符串的前...原创 2018-03-17 14:43:50 · 132 阅读 · 1 评论 -
LeetCode 15. 3Sum (和为零,求三元组)
题目描述: 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.注意:The solution set must not contain...原创 2018-03-17 15:09:51 · 711 阅读 · 0 评论 -
LeetCode 16. 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 would hav...原创 2018-03-17 15:20:11 · 235 阅读 · 0 评论 -
LeetCode 17. Letter Combinations of a Phone Number(电话号码→字母组合)
题目描述: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below.例子:Input: D...原创 2018-03-18 16:39:06 · 476 阅读 · 0 评论 -
LeetCode 18. 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.注意:The solution...原创 2018-03-18 16:48:42 · 264 阅读 · 0 评论 -
LeetCode 19. Remove Nth Node From End of List(删除单链表倒数第N个结点)
题目描述: Given a linked list, remove the nth node from the end of list and return its head.例子: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the en...原创 2018-03-18 17:27:55 · 169 阅读 · 0 评论 -
LeetCode 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 a...原创 2018-03-18 17:43:09 · 241 阅读 · 0 评论 -
LeetCode 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.例子:Input: 1->2->4, 1->3->4Output: 1-&...原创 2018-03-18 17:59:59 · 129 阅读 · 0 评论 -
LeetCode 22. Generate Parentheses(生成合法圆括号序列)
题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.例子(n=3):[ "((()))", "(()())", "(())()", "()(())", "()()()"]分析: 题意:给定数字n,需要...原创 2018-03-18 18:13:07 · 406 阅读 · 0 评论 -
LeetCode 23. Merge k Sorted Lists(合并k个有序单链表)
题目描述: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析: 题意:给定k个有序单链表,把他们合并成为一个有序单链表并返回。 思路:这道题是LeetCode 21的进化版本。看到这道题,脑海里首先联想到的是归并排序(Merge ...原创 2018-03-18 19:01:53 · 144 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs(按对交换单链表结点)
题目描述: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should ...原创 2018-03-18 19:21:33 · 191 阅读 · 0 评论 -
LeetCode 25. Reverse Nodes in k-Group(反转单链表每k个结点)
题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the...原创 2018-03-18 19:37:31 · 483 阅读 · 0 评论 -
LeetCode 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 m...原创 2018-03-18 19:52:03 · 164 阅读 · 0 评论 -
LeetCode 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 ar...原创 2018-03-19 12:45:00 · 249 阅读 · 0 评论 -
LeetCode 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.例子:Input: haystack = "hello", needle = "ll"Output: 2Input: hays...原创 2018-03-19 15:32:34 · 179 阅读 · 0 评论 -
LeetCode 29. Divide Two Integers(整数除法)
题目描述: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT.分析: 题意:给定两个整型数,求它们的商并返回(不能使用乘法、除法、取模运算符号,结果溢出则返回MAX_INT) 思路:由于各种运算符的限制...原创 2018-03-19 15:47:22 · 330 阅读 · 0 评论 -
LeetCode 30. 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 on...原创 2018-03-19 16:04:52 · 156 阅读 · 0 评论 -
LeetCode 31. Next Permutation(下一组排列)
题目描述: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest...原创 2018-03-19 16:20:45 · 190 阅读 · 0 评论 -
LeetCode 32. 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 "...原创 2018-03-19 17:13:13 · 385 阅读 · 0 评论 -
LeetCode 33. Search in Rotated Sorted Array(旋转有序数组,查找目标值Ⅰ)
题目描述: Suppose an array sorted in ascending order 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. ...原创 2018-03-19 17:50:43 · 247 阅读 · 0 评论 -
LeetCode 34. Search for a Range(有序数组,查找给定值范围)
题目描述: Given an array of integers sorted in ascending order, 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). ...原创 2018-03-19 18:02:46 · 360 阅读 · 0 评论 -
LeetCode 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 t...原创 2018-03-19 19:59:26 · 187 阅读 · 0 评论 -
LeetCode 36. Valid Sudoku(数独Ⅰ)
题目描述: Determine 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 '.'. 分析: 题意:给出一...原创 2018-03-19 20:07:54 · 107 阅读 · 0 评论 -
LeetCode 37. Sudoku Solver(数独Ⅱ)
题目描述: Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. ① A s...原创 2018-03-20 11:19:04 · 161 阅读 · 0 评论 -
LeetCode 38. Count and Say(计数和描述)
题目描述: The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 111221 1 is read off as "one 1" or 11. 11 i...原创 2018-03-20 11:42:10 · 141 阅读 · 0 评论 -
LeetCode 39. Combination Sum(给定和,求组合Ⅰ)
题目描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be ...原创 2018-03-20 12:10:04 · 187 阅读 · 0 评论 -
LeetCode 40. Combination Sum II(给定和,求组合Ⅱ)
题目描述: Given 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 once in the ...原创 2018-03-20 12:51:15 · 116 阅读 · 0 评论