LeetCode
冲鸭!!!!!
这个作者很懒,什么都没留下…
展开
-
LeetCode 62. Unique Paths
题目:机器人位于网格的左上角(下图中标记为“Start”)并试图到达网格的右下角(下图中标记为“Finish”)。机器人只能在任何时间点向下或向右移动。有多少种可能的路径?A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robo...原创 2019-07-22 15:48:46 · 174 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
题目:给定一个链表,判断它是否有一个循环。为了在给定的链表中表示一个循环,我们使用一个整数pos,它表示tail连接到的链表中的位置(0索引)。如果pos为-1,则链表中没有循环。Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, ...原创 2019-07-04 21:13:38 · 91 阅读 · 0 评论 -
LeetCode 155. Min Stack
题目:设计一个栈,支持push、pop、top和在常量时间内检索最小元素Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the e...原创 2019-07-04 20:32:19 · 114 阅读 · 0 评论 -
LeetCode 160. Intersection of Two Linked Lists
题目:找出两个单链表相交的起始点。Write a program to find the node at which the intersection of two singly linked lists begins.Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, s...原创 2019-07-04 19:51:35 · 156 阅读 · 0 评论 -
LeetCode 169. Majority Element
题目:给定一个大小为n的数组,找到多数元素。多数元素指至少⌊n / 2⌋次出现。可假设数组是非空的,并且存在符合条件的数。Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You m...原创 2019-07-04 19:21:38 · 176 阅读 · 0 评论 -
LeetCode 171. Excel Sheet Column Number
题目:给定Excel表中出现的列标题,返回对应的列号。Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 2...原创 2019-07-04 18:39:58 · 81 阅读 · 0 评论 -
剑指offer & LeetCode刷题分类记录
(个人记录,尚在更新)一、位运算二进制中1的个数 ——15https://blog.csdn.net/qq_22527013/article/details/88729605LeetCode 191. Number of 1 Bits ——https://blog.csdn.net/qq_22527013/article/details/93617793不用加减乘除做加...原创 2019-06-12 16:16:26 · 846 阅读 · 0 评论 -
LeetCode 172. Factorial Trailing Zeroes
题目:给定一个整数n,返回以n结尾的0的个数!Given an integern, return the number of trailing zeroes inn!.Input: 3 Output: 0 Explanation:3! = 6, no trailing zero.Input: 5 Output: 1 Explanation:5! = 12...原创 2019-07-04 17:11:51 · 106 阅读 · 0 评论 -
LeetCode 189. Rotate Array
题目:给定一个数组,将该数组向右旋转k步,其中k是非负的。Given an array, rotate the array to the right byksteps, wherekis non-negative.Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4]Input: [-1,-100,3,...原创 2019-07-04 15:32:49 · 84 阅读 · 0 评论 -
LeetCode 190. Reverse Bits
题目:Reverse bits of a given 32 bits unsigned integer反转给定32位无符号整数的位Input: 00000010100101000001111010011100Output: 00111001011110000010100101000000Explanation: The input binary string 0000001010...原创 2019-07-04 15:06:07 · 84 阅读 · 0 评论 -
LeetCode 34. Find First and Last Position of Element in Sorted Array
题目:给定一个按升序排序的整数数组,找出给定目标值的起始和结束位置运行时间复杂度O(log n),如果数组中没有目标,返回[- 1,1]。Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Yo...原创 2019-07-13 14:26:20 · 116 阅读 · 0 评论 -
LeetCode 22. Generate Parentheses
题目:给定n对括号,编写一个函数来生成所有格式良好的括号组合。Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))",...原创 2019-07-09 16:21:02 · 132 阅读 · 0 评论 -
LeetCode 19. 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.Given linked list: 1->2->3->4->5, and n = 2.After removing the secon...原创 2019-07-08 16:27:29 · 114 阅读 · 0 评论 -
LeetCode 17. Letter Combinations of a Phone Number
题目:给定一个包含2-9个数字的字符串,返回该数字可能表示的所有字母组合。下面给出了数字到字母的映射(就像电话按钮一样)。注意,1不映射到任何字母即:每个字符(数字)对应一个集合,输入字符串,求其对应的集合相同长度的排列Given a string containing digits from2-9inclusive, return all possible letter co...原创 2019-07-08 15:33:48 · 103 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II
题目:假设你有一个数组,其中第i个元素是某只股票在第i天的价格。设计一个算法来寻找最大的利润。您可以完成任意数量的事务(即,买进一股,再卖出一股)。必须先卖再买Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find...原创 2019-07-05 10:55:38 · 80 阅读 · 0 评论 -
LeetCode 29. Divide Two Integers
题目:给定两个整数的被除数和除数,在不使用乘法、除法和余运算符的情况下对两个整数进行除法;返回商;向零截断。被除数和除数都是32位带符号整数;除数永远不会是0假设我们处理的环境只能存储32位带符号整数范围内的整数:[- 2^31,2^31 - 1]。对于这个问题,假设函数在除法结果溢出时返回2^31 - 1。Given two integersdividendanddivis...原创 2019-07-10 15:29:44 · 144 阅读 · 0 评论 -
LeetCode 36. Valid Sudoku
题目:确定9x9数独板是否有效。只需要根据以下规则验证填充的单元格:1)每一行必须包含数字1-9,不能重复;2)每一列必须包含数字1-9,不能重复;3)网格的9个3x3子框中的每一个都必须包含数字1-9,不能重复。【注】数独板(部分填充)可能是有效的,但不一定是可解的。只需要根据上述规则验证填充的单元格。即检查:1)每行是否有重复2)每列是否有重复3)每个3×3...原创 2019-07-14 22:00:34 · 115 阅读 · 0 评论 -
LeetCode 36. Valid Sudoku
题目:给定一组区间,合并所有重叠的区间。Given a collection of intervals, merge all overlapping intervals.Input: [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] ...原创 2019-07-20 21:53:02 · 171 阅读 · 0 评论 -
LeetCode 73. Set Matrix Zeroes
题目:给定一个mxn矩阵,如果一个元素是0,把它的行和列都设为0(就在矩阵上进行修改)Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.跟进:空间复杂度:O(m×n) → O(m+n) → O(1)Input: [ [1,1,1],...原创 2019-07-29 22:06:07 · 170 阅读 · 0 评论 -
LeetCode 55. Jump Game
题目:给定一个非负整数数组,初始位置是数组的第一个索引。数组中的每个元素表示该位置的最大跳转长度。确定是否能够达到最后一个索引。Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the arra...原创 2019-07-20 00:24:56 · 160 阅读 · 0 评论 -
LeetCode 49. Group Anagrams
题目:Given an array of strings, group anagrams together.Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ]Note: All inputs wil...原创 2019-07-16 23:19:46 · 101 阅读 · 0 评论 -
LeetCode 48. Rotate Image
题目:你有一个n x n二维矩阵表示一个图像。将图像旋转90度(顺时针方向)。你必须原地旋转图像,这意味着你必须直接修改输入2D矩阵。不要分配另一个2D矩阵,做旋转。You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You...原创 2019-07-16 21:25:42 · 91 阅读 · 0 评论 -
LeetCode 33. Search in Rotated Sorted Array
题目:假设一个按升序排序的数组在某个未知的主轴上旋转。(即[0,1,2,4,5,6,7]可能变成[4,5,6,7,0,1,2])。给定要搜索的目标值。如果在数组中找到,返回它的索引,否则返回-1。可以假设数组中不存在,算法的运行时复杂度必须是O(log n)Suppose an array sorted in ascending order is rotated at s...原创 2019-07-12 16:27:43 · 109 阅读 · 0 评论 -
LeetCode 54. Spiral Matrix
题目:给定一个m x n个元素的矩阵(m行,n列),按螺旋顺序返回矩阵的所有元素。Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.[ [ 1, 2, 3 ], [ 4, 5, 6 ], Output:...原创 2019-07-18 16:35:17 · 120 阅读 · 0 评论 -
LeetCode 50. Pow(x, n)
题目:实现pow(x, n),即计算x的n次方(x^n)Implementpow(x,n), which calculatesxraised to the powern(x^n).Input: 2.00000, 10 Output: 1024.00000Input: 2.10000, 3 Output: 9.26100Input: 2.00000, -2...原创 2019-07-18 15:38:05 · 92 阅读 · 0 评论 -
LeetCode 15. 3Sum
题目:给定一个包含n个整数的数组,在数组中是否存在a、b、c元素使得a + b + c = 0?找出数组中所有唯一的三胞胎,它们的和为零注意:不能包含重复的三元组。Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique t...原创 2019-07-06 17:12:38 · 116 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
题目:给定n个非负整数a1 a2…,其中每个点表示坐标(i, ai)处的一个点。画出两条垂直线,使得直线i的两个端点分别为(i, ai)和(i, 0)。找出两条直线,这两条直线和x轴构成一个容器,使容器中含有最多的水。注意:你不能倾斜容器,n至少是2。即:找到数组中两个数,使【其中较小的数*两数之间的距离】最大Givennnon-negative integersa1,...原创 2019-07-06 13:46:45 · 108 阅读 · 0 评论 -
LeetCode 8. String to Integer (atoi)
题目:实现将字符串转换为整数。函数丢弃空白符,直到找到第一个非空白符。从首个非空白符开始,取一个可选的初始正负号,后跟尽可能多的数字,并将它们解释为一个数值。字符串可以包含构成整数的字符之后的附加字符,这些字符将被忽略,并且对函数的行为没有影响。如果str中的第一个非空格字符序列不是有效的整数,或者由于str为空或只包含空格字符而不存在这样的序列,则不执行转换。也就是说:字...原创 2019-07-06 13:19:11 · 123 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring
题目:给定一个字符串s,找出s中最长的回文子字符串。你可以假设s的最大长度是1000。Given a strings, find the longest palindromic substring ins. You may assume that the maximum length ofsis 1000.Input: "babad" Output: "bab" ...原创 2019-07-05 15:31:55 · 94 阅读 · 0 评论 -
LeetCode 46. Permutations
题目:给定一组不同的整数,返回所有可能的排列。Given a collection ofdistinctintegers, return all possible permutations.Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]方法:...原创 2019-07-14 22:44:12 · 95 阅读 · 0 评论 -
LeetCode 202. Happy Number
题目:编写一个算法来确定一个数字是否“幸福”快乐的数字定义为:从任何正整数,取代数的平方和的位数,并重复这个过程,直到数= 1(它将保持),或者它无休止地循环周期,不包括1。以1结束的那些数字是幸福的数字Write an algorithm to determine if a number is "happy"A happy number is a number defined b...原创 2019-06-24 14:57:30 · 131 阅读 · 0 评论 -
LeetCode 204. Count Primes
题目:小于非负数n的质数个数(不包括1)Count the number of prime numbers less than a non-negative number,n.Input: 10 Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.参考:https...原创 2019-06-24 14:29:53 · 108 阅读 · 0 评论 -
LeetCode 108. Convert Sorted Array to Binary Search Tree
题目:将排序后的数组转换为二叉搜索树描述:给定一个按升序排列元素的数组,将其转换为高度平衡的BST。对于该问题,高度平衡二叉树定义为每个节点的两个子树深度相差不超过1的二叉树Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For ...原创 2019-06-14 15:19:40 · 80 阅读 · 0 评论 -
LeetCode 326. Power of Three
题目:给定一个整数,写一个函数来确定它是否是3的幂。Given an integer, write a function to determine if it is a power of three.Input: 27 Output: trueInput: 0 Output: falseInput: 9 Output: trueInput: ...原创 2019-06-19 13:30:15 · 108 阅读 · 0 评论 -
LeetCode 344. Reverse String
题目:编写一个反转字符串的函数。输入字符串作为字符数组char[]给出。不要为另一个数组分配额外的空间,您必须使用O(1)额外内存修改输入数组。您可以假设所有字符都由可打印的ascii字符组成。Write a function that reverses a string. The input string is given as an array of charactersch...原创 2019-06-19 12:54:16 · 86 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree
题目:求二叉树的最大深度Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note:A leaf is a node...原创 2019-06-14 14:15:59 · 61 阅读 · 0 评论 -
LeetCode 101. Symmetric Tree
题目:给定一个二叉树,检查它是否是自身的镜像(即围绕其中心对称)。Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1...原创 2019-06-13 18:59:07 · 83 阅读 · 0 评论 -
LeetCode 88. Merge Sorted Array
题目:给定两个排序整数数组nums1和nums2,将nums2合并为一个排序数组nums1。nums1和nums2中初始化的元素数量分别为m和n。假设nums1有足够的空间(大小大于或等于m + n)来容纳nums2中的其他元素。Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one ...原创 2019-06-13 16:38:01 · 70 阅读 · 0 评论 -
LeetCode 70. Climbing Stairs
题目:爬n阶台阶,每次可爬1阶或2阶,可以用多少种不同的方式爬上去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 to...原创 2019-06-13 15:53:35 · 69 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
题目:计算并返回x的平方根,其中x保证是一个非负整数。由于返回类型是整数,因此将截断小数,只返回结果的整数部分。Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer. Since the return ty...原创 2019-06-13 15:34:31 · 92 阅读 · 0 评论