自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(141)
  • 收藏
  • 关注

原创 剑指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

原创 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 172

原创 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 176

原创 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 172

原创 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 161

原创 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 121

原创 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

原创 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 102

原创 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 92

原创 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 96

原创 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 117

原创 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 118

原创 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

原创 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 145

原创 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 133

原创 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 115

原创 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 104

原创 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

原创 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 110

原创 LeetCode 8. String to Integer (atoi)

题目:实现将字符串转换为整数。函数丢弃空白符,直到找到第一个非空白符。从首个非空白符开始,取一个可选的初始正负号,后跟尽可能多的数字,并将它们解释为一个数值。字符串可以包含构成整数的字符之后的附加字符,这些字符将被忽略,并且对函数的行为没有影响。如果str中的第一个非空格字符序列不是有效的整数,或者由于str为空或只包含空格字符而不存在这样的序列,则不执行转换。也就是说:字...

2019-07-06 13:19:11 124

原创 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 95

原创 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

原创 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

原创 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

原创 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

原创 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

原创 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

原创 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

原创 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

原创 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

原创 LeetCode 191. Number of 1 Bits

题目:编写一个函数,该函数接受一个无符号整数,并返回它拥有的“1”位的数量(也称为汉明权重)Write a function that takes an unsigned integer and returnthe number of '1'bits it has (also known as theHamming weight)Input: 00000000000000000...

2019-06-25 14:26:01 85

原创 LeetCode 198. House Robber

题目:你是一个计划沿街抢劫房屋的职业强盗。每个房子都有一定数量的钱被藏起来,阻止你抢劫他们的唯一限制是相邻的房子都有安全系统连接,如果两个相邻的房子在同一天晚上被闯入,它会自动联系警察。给出一个非负整数列表,表示每户人家的钱数,确定你今晚不报警就能抢劫的最大钱数。也就是说:给定一个非负整数列表,在不能取相邻两个数的情况下,求所取的所有数的最大和You are a professiona...

2019-06-25 14:08:43 164

原创 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 132

原创 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

原创 LeetCode 206. Reverse Linked List

题目:反转单链表Reverse a singly linked list.Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL思路:使用迭代来实现每次将原链表的头节点加入到另一个链表的头部中如1 2 3 4 5 null,先将1加入到新链表中,...

2019-06-21 15:45:18 74

原创 LeetCode 217. Contains Duplicate

题目:给定一个整数数组,查找该数组是否包含任何重复项。如果数组中出现任何值至少两次,函数应该返回true;如果每个元素都是不同的,函数应该返回false。Given an array of integers, find if the array contains any duplicates.Your function should return true if any value...

2019-06-21 14:58:22 96

原创 LeetCode 268. Missing Number

题目:给定一个数组,其中包含从0、1、2、…, n,找到数组中缺失的那个注意:算法应为线性运行时复杂度且使用恒定的额外空间复杂度Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.Input: [3,0...

2019-06-20 14:57:39 80

原创 LeetCode 283. Move Zeroes

题目:给定一个数组,编写一个函数将所有0移到数组末尾,同时保持非零元素的相对顺序注意:不能复制数组;最小化操作的总数。Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements....

2019-06-20 11:03:00 79

原创 LeetCode 231. Power of Two

题目:给定一个整数,写一个函数来确定它是否是2的幂。Given an integer, write a function to determine if it is a power of two.Input: 1 Output: true Input: 16 Output: true Input: 218 Output: fals...

2019-06-19 14:23:13 85

原创 LeetCode 342. Power of Four

题目:给定一个整数(有符号的32位),编写一个函数来检查它是否是4的幂。Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Input: 16 Output: trueInput: 5 Output: false方法:依次除以4,判断...

2019-06-19 14:17:10 120

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除