LeetCode 刷题
文章平均质量分 63
记录在LeetCode刷题的总结,C++&Java
大树先生的博客
生活是一棵长满可能的树
展开
-
LeetCode-24:Swap Nodes in Pairs(两两交换链表中的节点) -- Medium
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表原创 2018-08-07 10:33:27 · 1445 阅读 · 0 评论 -
LeetCode-32:Longest Valid Parentheses(最长有效括号) -- Hard
给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。原创 2018-08-03 12:41:59 · 2858 阅读 · 1 评论 -
LeetCode-20、22:Valid、Generate Parentheses(括号匹配、生成)
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。原创 2018-08-03 11:19:20 · 834 阅读 · 0 评论 -
LeetCode-14:Longest Common Prefix(最长公共前缀)
题目:Write a function to find the longest common prefix string amongst an array of strings.例子:Example 1:Input: ["flower","flow","flight"]Output: "fl"Example 2:Input: ["dog","racecar&qu原创 2018-08-02 09:41:44 · 960 阅读 · 0 评论 -
LeetCode-12:Integer to Roman(整数转罗马数字)
给定一个整数,将其转为罗马数字。原创 2018-07-30 10:47:30 · 1870 阅读 · 0 评论 -
LeetCode-8:String to Integer (atoi)(字符串转整数) -- Medium
将字符串转为整数原创 2018-07-27 10:36:22 · 863 阅读 · 0 评论 -
LeetCode-7:Reverse Integer(翻转整数)
给定一个 32 位有符号整数,将整数中的数字进行反转。原创 2018-07-25 21:14:32 · 1112 阅读 · 0 评论 -
LeetCode-6:ZigZag Conversion(Z字形变换)
将字符串s以Z字形排列成给定的行数之后从左往右,逐行读取字符。原创 2018-07-25 10:02:20 · 881 阅读 · 0 评论 -
LeetCode-5:Longest Palindromic Substring (最长回文字串)
给定一个字符串 s,找到 s 中最长的回文子串原创 2018-07-24 10:00:43 · 1294 阅读 · 0 评论 -
LeetCode-717:1-bit and 2-bit Characters (1位和2位编码元素)-- easy
给定数组中仅有0和1两种元素,且出现的元素组合只能有三种编码方式:`10`、`11`、`0`,判断给定的数组最后一个元素是否属于`0`编码,而不是`10`编码原创 2017-11-07 20:30:18 · 3105 阅读 · 0 评论 -
LeetCode-713:Subarray Product Less Than K (乘积小于K的子数组个数) -- medium
给定数组,和整数K,计数数组中所有满足元素乘积小于K的连续子数组的个数原创 2017-11-10 10:41:43 · 2326 阅读 · 0 评论 -
LeetCode-697:Degree of an Array (度相同的最小子数组)
给定非空非负整数数组,寻找最小连续子数组,使得子数组的度与原数组的度相同,返回子数组的长度原创 2017-10-20 10:05:35 · 5274 阅读 · 0 评论 -
LeetCode-695:Max Area of Island (最大岛的面积)
给定非空矩阵,元素为0或1,1代表陆地,四个方向中若有陆地相连,则代表区域,求最大区域的面积原创 2017-10-26 11:10:45 · 3766 阅读 · 0 评论 -
LeetCode-670:Maximum Swap (交换数字得最大整数) -- medium
给定非空非负整数,最多交换其中的两个数字,得到最大的整数,返回最大整数原创 2017-11-08 11:03:22 · 4036 阅读 · 0 评论 -
LeetCode-667:Beautiful Arrangement II (数组的完美安排) -- medium
给定整数n和k,构造一个包含1-n的n个整数的数组[a1, a2, a3, ... , an],使得[|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] 新数组含有k个不同的数原创 2017-11-09 21:02:55 · 1398 阅读 · 0 评论 -
LeetCode-665:Non-decreasing Array (判断是否为非递减数组)
给定数组,判断是否能够只修改一个元素,就可以使得数组是非递减数组原创 2017-10-25 09:40:21 · 2279 阅读 · 3 评论 -
LeetCode-661:Image Smoother (灰度图像平滑)
给定表示图像灰度的二维整数矩阵M,平滑图像,使每个单元格的灰度值成为所有包括周围8个单元格及其本身的平均灰度原创 2017-10-24 21:49:27 · 1477 阅读 · 0 评论 -
LeetCode-643:Maximum Average Subarray I (k个元素的最大子数组)
从数组中找到k个连续元素和最大的子数组,返回最大子数组的平均值原创 2017-10-20 09:49:03 · 974 阅读 · 0 评论 -
LeetCode-628:Maximum Product of Three Numbers (数组三元素最大乘积)
从数组中找到三个元素乘积的最大值,元素范围在[-1000,1000]内原创 2017-10-20 09:42:34 · 716 阅读 · 0 评论 -
LeetCode-624:Maximum Distance in Arrays (多数组找元素最大距离)
给定的多个按升序排序好的数组,从其中任意两个数组中各选择一个元素,计算两个元素的距离,找到最大距离。原创 2017-10-23 12:55:25 · 1307 阅读 · 1 评论 -
LeetCode-621:Task Scheduler (任务调度) -- medium
给定任务,在满足相同任务间隔的情况下,给出完成所有任务的时间原创 2017-11-10 12:47:06 · 5533 阅读 · 0 评论 -
LeetCode-605:Can Place Flowers (可放置花的数量)
给定0、1数组,0表示空,1表示非空,给定整数n,判断是否可以插入n个1,1不能相邻原创 2017-10-27 10:31:28 · 1410 阅读 · 1 评论 -
LeetCode-566:Reshape the Matrix (矩阵整型)-- easy
QuestionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-原创 2017-11-07 10:26:25 · 849 阅读 · 0 评论 -
LeetCode-532:K-diff Pairs in an Array (给定绝对值差的值对个数)
给定数组,找出所有差的绝对值为k的元素值对(i, j),返回元素值对的数量原创 2017-10-20 09:37:53 · 1415 阅读 · 0 评论 -
LeetCode-397:Integer Replacement (整数变1的步骤)
给定整数n,将整数逐步替换为1. 若为偶数则以n/2替换,若为奇数则可以以n+1或者n-1替换。求最小的替换步骤。原创 2018-05-08 10:51:41 · 995 阅读 · 0 评论 -
LeetCode-382:Linked List Random Node (随机返回链表结点)
设计一个类,该类能够实现随机返回链表中的一个结点。蓄水池算法原创 2018-05-16 16:50:07 · 1350 阅读 · 0 评论 -
LeetCode-347:Top K Frequent Elements (前K个频率最高的元素)
给定一个非空的整数数组,返回前K个频率最高的元素原创 2018-05-21 16:14:01 · 2365 阅读 · 0 评论 -
LeetCode-718:Maximum Length of Repeated Subarray (最长公共子数组) -- medium
给定两个数组A和B,寻找A和B中最长的公共子数组的长度原创 2017-11-09 13:40:27 · 2169 阅读 · 0 评论 -
LeetCode-674:Longest Continuous Increasing Subsequence (最长连续增序列)
给定数组,找到其中最长的连续递增的子数组序列原创 2017-10-26 10:22:27 · 853 阅读 · 0 评论 -
LeetCode-581:Shortest Unsorted Continuous Subarray (最短未排序连续子数组) -- easy
给定整数数组,找到一个最短的连续的未按照升序排序的最短子数组,返回子数组的长度原创 2017-11-07 15:32:49 · 2667 阅读 · 0 评论 -
LeetCode-300:Longest Increasing Subsequence (最长递增子序列)
求数组的最长递增子序列的长度 & 子序列原创 2018-04-24 11:40:16 · 2006 阅读 · 0 评论 -
LeetCode-283:Move Zeroes (将数组中0元素移至尾部)
给定数组,将数组中的0元素移至数组末尾,非零元素顺序不变原创 2017-10-25 10:19:44 · 1890 阅读 · 0 评论 -
LeetCode-448:Find All Numbers Disappeared in an Array (寻找缺失多个数字)
给定含有n个元素的数组,每个元素大小满足 1 ≤ a[i] ≤ n,找出其中缺少的元素。原创 2017-10-26 09:50:54 · 1621 阅读 · 0 评论 -
LeetCode-268:Missing Number(寻找缺失数字)
从给定不含重复元素的数组中,找到缺失数字,从0~n原创 2017-10-19 17:41:26 · 3382 阅读 · 0 评论 -
LeetCode-243:Shortest Word Distance (单词最短距离)
给定单词list,返回其中任意两单词的最短位置距离原创 2017-10-25 10:46:36 · 1582 阅读 · 0 评论 -
LeetCode-228:Summary Ranges (总结范围)
给定一个递增排序的数组,给出数组的范围总结原创 2018-04-25 11:35:26 · 767 阅读 · 0 评论 -
LeetCode-219:Contains Duplicate II (一定范围内的两相同元素)
给定数组中,找出两个不同的索引 i 和 j,有 nums[i]=num[j],且绝对差值小于等于 k原创 2017-10-19 21:30:52 · 857 阅读 · 0 评论 -
LeetCode-198 & 213:House Robber (房屋抢劫)
每个房间里都有不同数量的财物,给出能抢劫的最大财物数。不能同时对相邻的房间进行抢劫。原创 2018-04-20 10:24:02 · 2159 阅读 · 0 评论 -
LeetCode-189:Rotate Array (数组的循环移位)
将数组右边k元素移到数组头部,循环移位原创 2017-10-19 21:34:09 · 3680 阅读 · 0 评论 -
LeetCode-169:Majority Element (数组中的多数元素)
给定大小n的数组,找到其中多数元素。其中多数元素是超过n/2个的重复元素原创 2017-10-19 21:46:55 · 928 阅读 · 0 评论