![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 76
susandebug
keep moving
展开
-
LeetCode题解——2Add 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原创 2015-06-27 20:17:12 · 596 阅读 · 0 评论 -
LeetCode题解——3Longest 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-27 20:46:54 · 467 阅读 · 0 评论 -
LeetCode题解——1TwoSum
题目: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原创 2015-06-27 11:17:36 · 440 阅读 · 0 评论 -
LeetCode题解——7Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: int reverse(int x) { long result=0; while(x!=0) { result = re原创 2015-07-11 13:14:37 · 475 阅读 · 0 评论 -
LeetCode题解——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). Fin原创 2015-07-11 16:31:38 · 449 阅读 · 0 评论 -
LeetCode题解——6ZigZag 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原创 2015-07-11 13:11:41 · 460 阅读 · 0 评论 -
LeetCode题解——4Median of Two Sorted Arrays
Median of Two Sorted ArraysThere 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+原创 2015-07-03 19:58:47 · 507 阅读 · 0 评论 -
LeetCode题解——Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { string M[4] = {"原创 2015-07-12 20:01:14 · 556 阅读 · 0 评论 -
LeetCode题解——Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.以第一个str作为比较标准。class Solution {public: string longestCommonPrefix(vector& strs) { if(strs原创 2015-07-12 20:52:48 · 412 阅读 · 0 评论 -
LeetCode题解——Trapping Rain Water
Given 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,1,0,2,1,0,1,3,2,1,2,1]原创 2015-07-11 16:25:04 · 598 阅读 · 0 评论 -
LeetCode题解——10Regular 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 entire i原创 2015-07-11 13:02:32 · 671 阅读 · 0 评论 -
LeetCode题解——8 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 yourself what are the possible input ca原创 2015-07-11 13:18:08 · 479 阅读 · 0 评论 -
LeetCode题解——9Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: bool isPalindrome(int x) { if(x<0||(x!=0&&x%10==0)) return false; i原创 2015-07-11 13:21:50 · 427 阅读 · 0 评论 -
LeetCode题解——3Sum
iven 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-07-12 22:11:42 · 522 阅读 · 0 评论 -
LeetCode题解——Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: int romanToInt(string s) { int base[128];原创 2015-07-12 19:58:50 · 526 阅读 · 0 评论 -
LeetCode题解——Generate Parentheses
做了一些题目之后,发现使用递归的地方和使用回溯的地方也可以使用动态规划来求解,而且动态规划求解更加易于理解和实现,算法的效率更高。//递归方法class Solution {public: vector generateParenthesis(int n) { vector ans; if(n==0){ string s=""原创 2015-07-14 19:49:42 · 504 阅读 · 0 评论 -
LeetCode题解——Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne原创 2015-07-28 16:39:43 · 516 阅读 · 0 评论 -
LeetCode题解——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原创 2015-07-14 19:53:51 · 449 阅读 · 0 评论 -
LeetCode题解——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原创 2015-07-14 20:14:27 · 441 阅读 · 0 评论 -
LeetCode题解——Sort List
Sort a linked list in O(n log n) time using constant space complexity.用冒泡:时间超出用归并:成功解决/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *原创 2015-07-28 16:13:06 · 384 阅读 · 0 评论 -
LeetCode题解——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:Element原创 2015-07-14 20:02:58 · 472 阅读 · 0 评论 -
LeetCode题解——Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone b原创 2015-07-14 20:09:36 · 509 阅读 · 0 评论 -
LeetCode题解——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 use only constant space. Y原创 2015-07-28 19:14:35 · 400 阅读 · 0 评论 -
LeetCode题解——Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.c原创 2015-07-29 10:42:42 · 463 阅读 · 0 评论 -
LeetCode题解——Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updat原创 2015-07-29 14:25:50 · 420 阅读 · 0 评论 -
LeetCode题解——Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2015-07-29 10:18:41 · 415 阅读 · 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原创 2015-07-29 10:45:10 · 533 阅读 · 0 评论 -
LeetCode题解——Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with val原创 2015-07-29 14:06:30 · 517 阅读 · 0 评论 -
LeetCode题解——Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) { long a =原创 2015-07-29 15:48:57 · 445 阅读 · 0 评论 -
LeetCode题解——Combination Sum
Given 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 C unlimited number原创 2015-08-25 21:16:17 · 681 阅读 · 0 评论 -
LeetCode题解——Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB class Solut原创 2015-07-31 09:50:29 · 543 阅读 · 0 评论 -
LeetCode题解——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 combinati原创 2015-08-26 20:09:21 · 767 阅读 · 0 评论 -
LeetCode题解——Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi原创 2015-08-26 21:51:17 · 651 阅读 · 0 评论 -
LeetCode题解——permutations
Given 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].using rec原创 2015-08-27 09:02:46 · 516 阅读 · 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.//用递归,不会占用额外的空间,如果是直接比较会占用额外的空间,大小与两个链表的长度成正比/** * D原创 2015-07-21 21:15:11 · 476 阅读 · 0 评论 -
LeetCode题解——Permutation总结
Leetcode Permutation总结含其中四题:Next Permutation, Permutations, Permutations II, Permutation SequenceNext PermutationImplement next permutation, which rearranges numbers into the lexicogra转载 2015-08-28 10:18:59 · 1354 阅读 · 0 评论 -
LeetCode题解——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 add原创 2015-07-21 21:12:25 · 571 阅读 · 0 评论 -
LeetCode题解——Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2015-08-26 21:32:51 · 466 阅读 · 0 评论 -
LeetCode题解——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原创 2015-08-31 16:43:27 · 476 阅读 · 0 评论 -
LeetCode题解——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 '.'.A partially filled sudoku which原创 2015-09-01 19:09:20 · 533 阅读 · 0 评论