LEETCODE C++
クロネコ黒猫
这个作者很懒,什么都没留下…
展开
-
从零开始的LC刷题(134): Spiral Matrix
原题;Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,...原创 2019-11-15 20:16:30 · 88 阅读 · 0 评论 -
从零开始的LC刷题(133): Pow(x, n)
原题:Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.0...原创 2019-11-15 19:37:35 · 138 阅读 · 0 评论 -
从零开始的LC刷题(132): Rotate Image
原题:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D ma...原创 2019-11-11 19:03:44 · 125 阅读 · 0 评论 -
从零开始的LC刷题(131): Permutations II
原题:Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]给出有重复数字的数列的全排列,在上一题...原创 2019-11-08 20:06:24 · 102 阅读 · 0 评论 -
从零开始的LC刷题(130): Permutations
原题:Given a collection ofdistinctintegers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]求出给出数列的全排列,递归...原创 2019-11-08 19:34:48 · 107 阅读 · 0 评论 -
从零开始的LC刷题(129): Multiply Strings
原题:Given two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"...原创 2019-11-08 18:49:11 · 129 阅读 · 0 评论 -
从零开始的LC刷题(128): Combination Sum II
原题:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidat...原创 2019-11-07 19:18:59 · 105 阅读 · 0 评论 -
从零开始的LC刷题(127): Combination Sum
原题:Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesame...原创 2019-11-07 19:01:56 · 191 阅读 · 0 评论 -
从零开始的LC刷题(126): Valid Sudoku
原题:Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must...原创 2019-10-31 18:00:34 · 98 阅读 · 0 评论 -
从零开始的LC刷题(125): Find First and Last Position of Element in Sorted Array
原题:Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Your algorithm's runtime complexity must be in the order ofO(logn).I...原创 2019-10-31 15:31:23 · 85 阅读 · 0 评论 -
从零开始的LC刷题(124): 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. If ...原创 2019-10-31 14:42:29 · 110 阅读 · 0 评论 -
从零开始的LC刷题(123): Next Permutation
原题:Implementnext 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 poss...原创 2019-10-30 19:44:10 · 102 阅读 · 0 评论 -
从零开始的LC刷题(122): Swap Nodes in Pairs
原题;Given alinked list, swap every two adjacent nodes and return its head.You maynotmodify the values in the list's nodes, only nodes itself may be changed.Example:Given 1->2->3-&...原创 2019-10-28 19:33:12 · 91 阅读 · 0 评论 -
从零开始的LC刷题(121): Generate Parentheses
原题:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", "(...原创 2019-10-28 19:15:33 · 146 阅读 · 0 评论 -
从零开始的LC刷题(120): Remove Nth Node From End of List 移除链表中倒数第n个元素
原题:Given a linked list, remove then-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 the second node from the ...原创 2019-10-28 18:13:35 · 140 阅读 · 1 评论 -
从零开始的LC刷题(119): Letter Combinations of a Phone Number
原题:Given a string containing digits from2-9inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) ...原创 2019-10-16 19:10:30 · 208 阅读 · 0 评论 -
从零开始的LC刷题(118): 3Sum Closest
原题:Given an arraynumsofnintegers and an integertarget, find three integers innumssuch that the sum is closest totarget. Return the sum of the three integers. You may assume that each input ...原创 2019-10-16 19:01:22 · 80 阅读 · 0 评论 -
从零开始的LC刷题(117)*: 3Sum
原题:Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must no...原创 2019-10-15 19:39:33 · 162 阅读 · 0 评论 -
从零开始的LC刷题(116)*: Integer to Roman
原题:Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-10-15 18:34:05 · 123 阅读 · 0 评论 -
从零开始的LC刷题(115)*: Container With Most Water
原题:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Fi...原创 2019-10-15 18:25:08 · 111 阅读 · 0 评论 -
包含小数处理的c++超长数字乘法计算器
将数字以字符串形式存储和处理,包含小数处理#include <iostream>#include <string>#include <cctype>using namespace std;int toint(char n) { switch (n) { case '1': return 1; ...原创 2018-09-15 09:59:02 · 1474 阅读 · 1 评论 -
从零开始的LC刷题(13)*: Maximum Subarray
原题:Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Exp...原创 2019-04-26 11:54:26 · 178 阅读 · 0 评论 -
从零开始的LC刷题(14): Length of Last Word
原题:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:A word is...原创 2019-04-26 12:13:05 · 107 阅读 · 0 评论 -
从零开始的LC刷题(15): Plus One
原题:Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each e...原创 2019-04-26 12:38:36 · 910 阅读 · 0 评论 -
从零开始的LC刷题(2): 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: 21Note:Assume we a...原创 2019-04-22 15:52:01 · 145 阅读 · 0 评论 -
从零开始的LC刷题(3): Palindrome Number
原题:Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: fals...原创 2019-04-22 17:52:58 · 145 阅读 · 0 评论 -
从零开始的LC刷题(4): Roman to Integer
原题比较长:Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-23 11:56:12 · 109 阅读 · 0 评论 -
从零开始的LC刷题(5): Longest Common Prefix
原题:Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".Example 1:Input: ["flower","flow","flight"]O...原创 2019-04-23 16:19:16 · 99 阅读 · 0 评论 -
从零开始的LC刷题(6): Valid Parentheses
原题:Given 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 the same typ...原创 2019-04-23 17:56:07 · 139 阅读 · 0 评论 -
从零开始的LC刷题(7): 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.Example:Input: 1->2->4, 1->3->4Outp...原创 2019-04-23 23:41:52 · 119 阅读 · 0 评论 -
从零开始的LC刷题(8): Remove Duplicates from Sorted Array
原题:Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bym...原创 2019-04-24 11:56:38 · 122 阅读 · 0 评论 -
从零开始的LC刷题(9): Remove Element
原题:Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the inpu...原创 2019-04-24 12:58:15 · 119 阅读 · 0 评论 -
从零开始的LC刷题(10): Implement strStr() 字符串匹配
原题:ImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2E...原创 2019-04-24 18:23:10 · 131 阅读 · 0 评论 -
从零开始的LC刷题(11): 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 ar...原创 2019-04-25 10:44:21 · 152 阅读 · 0 评论 -
从零开始的LC刷题(12): 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. 1112211is read off as"one 1"or11.11is rea...原创 2019-04-25 13:02:12 · 162 阅读 · 0 评论 -
从零开始的LC刷题(16): Add Binary
原题:Given two binary strings, return their sum (also a binary string).The input strings are bothnon-emptyand contains only characters1or0.Example 1:Input: a = "11", b = "1"Output: "100"...原创 2019-05-09 18:21:52 · 134 阅读 · 0 评论 -
从零开始的LC刷题(17): Sqrt(x)
原题:Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer.Since the return typeis an integer, the decimal digits are truncated an...原创 2019-05-09 19:04:06 · 149 阅读 · 0 评论 -
从零开始的LC刷题(28): Path Sum
原题:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note:A leaf is a node with no children.Ex...原创 2019-05-24 17:19:29 · 124 阅读 · 0 评论 -
从零开始的LC刷题(18): Climbing Stairs 动态规划基础题
原题:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:Givennwill be a po...原创 2019-05-11 15:40:59 · 207 阅读 · 0 评论 -
从零开始的LC刷题(29): Pascal's Triangle 帕斯卡三角形(杨辉三角)
原题:Given a non-negative integernumRows, generate the firstnumRowsof Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:Input: 5O...原创 2019-05-24 18:45:06 · 278 阅读 · 0 评论