leetcode
Mark-Wang
菜鸟逆袭记
展开
-
LeetCode第50题:Pow(x, n)(Java详解)
题目解析:实现幂次方解题思路:递归调用最是方便,也是递归最经典用法代码:class Solution { public double myPow(double x, int n) { if (n == 0){ return 1; } if (n == 1){ return x; } if (n == -1){ return 1/x; .原创 2020-08-16 17:32:42 · 242 阅读 · 0 评论 -
LeetCode第49题:Group Anagrams(Java详解)
Given an array of strings, group anagrams together.Example:Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Output:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]Note:All inputs will be in lowercase.The order of your output does not matter.题目解析:同原创 2020-08-16 17:16:07 · 313 阅读 · 0 评论 -
LeetCode第37题:Sudoku Solver(Java、C++详解)
Write a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of the ...原创 2019-12-31 13:32:39 · 205 阅读 · 0 评论 -
LeetCode第36题:Valid Sudoku(Java、C++详解)
Valid SudokuDetermine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:1.Each row must contain the digits 1-9 without repetition.2.Each ...原创 2019-12-29 16:43:48 · 277 阅读 · 0 评论 -
LeetCode第33题:Search in Rotated Sorted Array(Java详解)
Search in Rotated Sorted ArraySuppose 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 ta...原创 2019-12-15 18:26:39 · 333 阅读 · 0 评论 -
LeetCode第25题:Reverse Nodes in k-Group(C++详解)
Reverse Nodes in k-GroupGiven 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 link...原创 2019-09-01 18:24:00 · 229 阅读 · 0 评论 -
LeetCode第24题:Swap Nodes in Pairs(C++)详解
Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Given 1->...原创 2019-08-25 17:55:46 · 188 阅读 · 0 评论 -
LeetCode第23题:Merge k Sorted Lists(C++)详解
Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[1->4->5,1->3->4,2->6]Output: 1->1->...原创 2019-08-25 16:35:12 · 318 阅读 · 0 评论 -
LeetCode第22题:Generate Parentheses(C++)详解
Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())(...原创 2019-08-18 18:23:32 · 257 阅读 · 0 评论 -
LeetCode第26题:Remove Duplicates from Sorted Array(C++详解)
Remove Duplicates from Sorted ArrayGiven a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for anoth...原创 2019-09-01 19:30:54 · 114 阅读 · 0 评论 -
LeetCode第27题:Remove Element(C++详解)
Given an array nums and a value val, 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 array...原创 2019-09-08 17:36:30 · 144 阅读 · 0 评论 -
LeetCode第28题:Implement strStr()(C++详解)
28.Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = “hello”, needle = “ll”Output: 2Example 2:...原创 2019-09-08 17:47:58 · 288 阅读 · 1 评论 -
LeetCode第29题:Divide Two Integers(C++图文详解)
Divide Two IntegersGiven two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The ...原创 2019-09-14 19:44:10 · 251 阅读 · 0 评论 -
LeetCode第30题:Substring with Concatenation of All Words(C++图文详解)
Substring with Concatenation of All WordsYou 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 concatenatio...原创 2019-09-15 12:20:17 · 249 阅读 · 0 评论 -
LeetCode第31题:Next Permutation(C++图文详解)
Next PermutationImplement 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...原创 2019-09-22 19:49:20 · 293 阅读 · 0 评论 -
LeetCode第32题:Longest Valid Parentheses(C++详解)
Longest Valid ParenthesesGiven a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: “(()”Output: 2Expla...原创 2019-10-07 17:53:30 · 210 阅读 · 0 评论 -
LeetCode第21题:Merge Two Sorted Lists(C++)详解
Merge Two Sorted ListsMerge 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.Example:Input: 1->2->4, 1-...原创 2019-08-18 16:53:13 · 193 阅读 · 0 评论 -
LeetCode第20题:Valid Parentheses(C++详解)
Valid ParenthesesGiven a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by ...原创 2019-07-28 17:58:53 · 393 阅读 · 0 评论 -
LeetCode第五题:Longest Palindromic Substring(c++)详解
LeetCode:第五题Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “bab”N...原创 2019-04-21 21:45:33 · 441 阅读 · 0 评论 -
LeetCode第六题:ZigZag Conversion(C++)图文详解
ZigZag Conversion题目中举了二个例子:The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display thispattern in a fixed font for better legibility...原创 2019-04-23 22:41:06 · 686 阅读 · 1 评论 -
LeetCoded第七题:Reverse Integer(C++)详解
Reverse Integer题目描述:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21题目解析:一看题目就是整数逆...原创 2019-04-28 20:58:53 · 383 阅读 · 0 评论 -
LeetCode第八题:String to Integer (atoi)(C++)
String to Integer (atoi)Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found....原创 2019-05-05 21:22:59 · 217 阅读 · 0 评论 -
LeetCode第15题:3Sum(C++)详解
3SumGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not c...原创 2019-05-13 21:20:55 · 547 阅读 · 0 评论 -
LeetCode第九题:Palindrome Number(C++)
Palindrome NumberDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output:...原创 2019-05-06 21:18:51 · 513 阅读 · 0 评论 -
LeetCode第11题:Container With Most Water(C++)详解
Container With Most WaterGiven 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, ...原创 2019-05-09 20:36:48 · 399 阅读 · 0 评论 -
LeetCode第十题:Regular Expression Matching(C++)详解
Regular Expression MatchingGiven an input string (s) and a pattern §, implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character.‘*’ Matches zero or more of...原创 2019-05-07 20:42:10 · 563 阅读 · 0 评论 -
LeetCode第12题:Integer to Roman(C++)
Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 1...原创 2019-05-10 21:14:21 · 384 阅读 · 0 评论 -
LeetCode第13题:Roman to Integer(C++)详解
Roman to IntegerRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 1...原创 2019-05-10 21:57:27 · 668 阅读 · 0 评论 -
LeetCode第14题:Longest Common Prefix(C++)详解
明确自己目标后,既充实自己,又不焦虑,完美。继续LeetCodeLongest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”....原创 2019-05-12 21:34:24 · 542 阅读 · 0 评论 -
LeetCode第16题:3Sum Closest(C++详解)
3Sum ClosestGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that eac...原创 2019-06-09 17:47:05 · 202 阅读 · 0 评论 -
LeetCode第18题:4Sum(C++详解)
4SumGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum ...原创 2019-07-07 21:39:34 · 207 阅读 · 0 评论 -
LeetCode第17题:Letter Combinations of a Phone Number(C++详解)
Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (jus...原创 2019-06-30 18:31:31 · 571 阅读 · 0 评论 -
LeetCode第19题:Remove Nth Node From End of List(C++详解)
Remove Nth Node From End of ListGiven a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing ...原创 2019-07-28 16:51:34 · 158 阅读 · 0 评论 -
LeetCode第四题:Median of Two Sorted Arrays(c++)详解
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+n))....原创 2019-04-20 17:27:31 · 481 阅读 · 0 评论