
LeetCode
文章平均质量分 71
持之以恒-zx
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode-200. 岛屿数量
给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。此外,你可以假设该网格的四条边均被水包围。示例 1:输入:11110110101100000000输出: 1示例 2:输入:11000110000010000011输出: 3解释: 每座...原创 2020-04-20 16:53:51 · 197 阅读 · 0 评论 -
LeetCode-56. 合并区间
给出一个区间的集合,请合并所有重叠的区间。示例 1:输入: [[1,3],[2,6],[8,10],[15,18]]输出: [[1,6],[8,10],[15,18]]解释: 区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].示例 2:输入: [[1,4],[4,5]]输出: [[1,5]]解释: 区间 [1,4] 和 [4,5] 可被视为重叠区间。...原创 2020-04-16 15:59:38 · 343 阅读 · 0 评论 -
LeetCode-1111. 有效括号的嵌套深度
有效括号字符串 定义:对于每个左括号,都能找到与之对应的右括号,反之亦然。详情参见题末「有效括号字符串」部分。嵌套深度 depth 定义:即有效括号字符串嵌套的层数,depth(A) 表示有效括号字符串 A 的嵌套深度。详情参见题末「嵌套深度」部分。 给你一个「有效括号字符串」 seq,请你将其分成两个不相交的有效括号字符串,A 和 B,并使这两个字符串的深度最小。 不相交...原创 2020-04-01 16:32:19 · 228 阅读 · 0 评论 -
LeetCode-482. 密钥格式化
给定一个密钥字符串S,只包含字母,数字以及 '-'(破折号)。N 个 '-' 将字符串分成了 N+1 组。给定一个数字 K,重新格式化字符串,除了第一个分组以外,每个分组要包含 K 个字符,第一个分组至少要包含 1 个字符。两个分组之间用 '-'(破折号)隔开,并且将所有的小写字母转换为大写字母。给定非空字符串 S 和数字 K,按照上面描述的规则进行格式化。示例 1:输入:S = "...原创 2020-02-22 14:33:28 · 244 阅读 · 0 评论 -
LeetCode-665. 非递减数列 and LeetCode-669. 修剪二叉搜索树
LeetCode-665给定一个长度为n的整数数组,你的任务是判断在最多改变1 个元素的情况下,该数组能否变成一个非递减数列。我们是这样定义一个非递减数列的:对于数组中所有的i (1 <= i < n),满足array[i] <= array[i + 1]。示例 1:输入: [4,2,3]输出: True解释: 你可以通过把第一个4变成1来使得它成...原创 2020-02-17 17:35:44 · 191 阅读 · 0 评论 -
LeetCode-643. 子数组最大平均数 I and LeetCode-645. 错误的集合
LeetCode-643给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。示例 1:输入: [1,12,-5,-6,50,3], k = 4输出: 12.75解释: 最大平均数 (12-5-6+50)/4 = 51/4 = 12.75solution:class Solution: def findMaxAverage(self...原创 2020-02-15 16:38:27 · 164 阅读 · 0 评论 -
LeetCode-476. 数字的补数 and LeetCode-412. Fizz Buzz
LeetCode-476给定一个正整数,输出它的补数。补数是对该数的二进制表示取反。注意:给定的整数保证在32位带符号整数的范围内。你可以假定二进制数不包含前导零位。示例 1:输入: 5输出: 2解释: 5的二进制表示为101(没有前导零位),其补数为010。所以你需要输出2。示例 2:输入: 1输出: 0解释: 1的二进制表示为1(没有前导零位),其补数为0。所...原创 2020-02-13 17:06:01 · 195 阅读 · 0 评论 -
LeetCode-34. 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).If the...原创 2019-07-04 14:43:36 · 131 阅读 · 0 评论 -
LeetCode-31. 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 possible o...原创 2019-07-03 11:06:14 · 174 阅读 · 0 评论 -
LeetCode-24. 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->4, ...原创 2019-07-02 15:58:39 · 153 阅读 · 0 评论 -
LeetCode-19. Remove Nth Node From End of List
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 end, t...原创 2019-07-01 10:00:46 · 129 阅读 · 0 评论 -
LeetCode-11. 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). Find two...原创 2019-06-30 14:58:04 · 134 阅读 · 0 评论 -
LeetCode-6. ZigZag Conversion
6.ZigZag ConversionMedium10683338FavoriteShareThe string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed fo...原创 2019-06-29 19:41:04 · 204 阅读 · 0 评论 -
LeetCode-7. 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 are dea...原创 2019-06-28 16:03:06 · 305 阅读 · 0 评论 -
LeetCode-455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo...原创 2019-06-27 15:51:11 · 148 阅读 · 0 评论 -
LeetCode-190. 颠倒二进制位
颠倒给定的 32 位无符号整数的二进制位。示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 00000010100101000001111010011100 , 返回 964176192,其二进制表示形式为 00111001011110000010100101000000 。 ...转载 2019-08-29 16:32:37 · 141 阅读 · 0 评论 -
LeetCode-92. 反转链表 II
我一开始想到了链表的头插法,因为头插法创建的链表序列是逆序的,但是这题我不太会写..看了一下大佬的解答,发现其实应该是能写的,但是需要用一些辅助指针,而且要会用思路要清晰,这种思想对于解决链表这类的问题很重要,要理解并会使用,转载备查转自https://leetcode-cn.com/problems/reverse-linked-list-ii/solution/using...转载 2019-09-04 23:19:30 · 140 阅读 · 0 评论 -
LeetCode-93. 复原IP地址
代码思路来自https://leetcode-cn.com/problems/restore-ip-addresses/solution/bao-li-he-hui-su-by-powcai/将java的代码学习并修改成了C++代码备查solution:class Solution {public: vector<string> restoreIpAddr...转载 2019-09-05 23:40:54 · 181 阅读 · 0 评论 -
LeetCode-67. 二进制求和
给定两个二进制字符串,返回他们的和(用二进制表示)。输入为非空字符串且只包含数字 1 和 0。示例 1:输入: a = "11", b = "1"输出: "100"示例 2:输入: a = "1010", b = "1011"输出: "10101"solution:class Solution { public static String ad原创 2018-08-23 17:46:01 · 137 阅读 · 0 评论 -
LeetCode-116. Populating Next Right Pointers in Each Node
Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right...原创 2018-12-02 23:12:31 · 151 阅读 · 0 评论 -
Leetcode-937. 重新排列日志文件
你有一个日志数组 logs。每条日志都是以空格分隔的字串。对于每条日志,其第一个字为字母数字标识符。然后,要么:标识符后面的每个字将仅由小写字母组成,或; 标识符后面的每个字将仅由数字组成。我们将这两种日志分别称为字母日志和数字日志。保证每个日志在其标识符后面至少有一个字。将日志重新排序,使得所有字母日志都排在数字日志之前。字母日志按字母顺序排序,忽略标识符,标识符仅用于表示关系。...原创 2018-11-11 16:29:08 · 884 阅读 · 2 评论 -
LeetCode-312 Burst Balloons
转自https://blog.youkuaiyun.com/jmspan/article/details/51208865原题网址:https://leetcode.com/problems/burst-balloons/Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it repres...转载 2018-11-09 15:19:23 · 151 阅读 · 0 评论 -
LeetCode-2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-10-03 15:36:17 · 146 阅读 · 0 评论 -
LeetCode-650. 只有两个键的键盘
最初在一个记事本上只有一个字符 'A'。你每次可以对这个记事本进行两种操作:Copy All (复制全部) : 你可以复制这个记事本中的所有字符(部分的复制是不允许的)。 Paste (粘贴) : 你可以粘贴你上一次复制的字符。给定一个数字 n 。你需要使用最少的操作次数,在记事本中打印出恰好 n 个 'A'。输出能够打印出 n 个 'A' 的最少操作次数。示例 1:输入: 3...原创 2018-09-30 20:50:36 · 498 阅读 · 0 评论 -
LeetCode-83. 删除排序链表中的重复元素
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。示例 1:输入: 1->1->2输出: 1->2示例 2:输入: 1->1->2->3->3输出: 1->2->3class Solution { public ListNode deleteDuplicates(ListNode head)...原创 2018-08-24 01:31:07 · 96 阅读 · 0 评论 -
LeetCode-70. 爬楼梯
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?注意:给定 n 是一个正整数。示例 1:输入: 2输出: 2解释: 有两种方法可以爬到楼顶。1. 1 阶 + 1 阶2. 2 阶示例 2:输入: 3输出: 3解释: 有三种方法可以爬到楼顶。1. 1 阶 + 1 阶 + 1 阶2. ...原创 2018-08-23 18:10:36 · 118 阅读 · 0 评论 -
LeetCode-15 三数之和
这是我写的第二道LeetCode题,LeetCode可以,刷了!转自https://blog.youkuaiyun.com/qq_35170267/article/details/81031368 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。 注意:答案中不可以包含重复的三元...转载 2018-08-20 22:29:14 · 172 阅读 · 0 评论 -
LeetCod-107. 二叉树的层次遍历 II
转自https://blog.youkuaiyun.com/qq_37765748/article/details/79937086给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶节点所在层到根节点所在的层,逐层从左向右遍历)例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其自...转载 2018-08-27 09:07:52 · 206 阅读 · 0 评论 -
LeetCode-38. 报数
报数序列是指一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下:1. 12. 113. 214. 12115. 1112211 被读作 "one 1" ("一个一") , 即 11。11 被读作 "two 1s" ("两个一"), 即 21。21 被读作 "one 2", "one 1" ("一原创 2018-08-22 23:46:16 · 134 阅读 · 0 评论 -
LeetCode-26. 删除排序数组中的重复项
灵巧的方法转自https://blog.youkuaiyun.com/youyoulanyouyou/article/details/79574769给定一个有序数组,删除重复内容,使每个元素只出现一次,并返回新的长度。不要为其他数组分配额外的空间,您必须通过在 o(1)额外的内存中修改输入数组来实现。例如:nums[]={5 5 5 6 7 7 7 7 9 9 9 9 9} 有4个不同...转载 2018-08-22 17:12:13 · 149 阅读 · 0 评论 -
LeetCode-563 Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree ...原创 2018-10-11 16:31:31 · 232 阅读 · 0 评论 -
LeetCode-413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:...原创 2018-10-04 14:57:38 · 122 阅读 · 0 评论 -
LeetCode-605 Can Plac Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Give...原创 2018-10-13 09:47:04 · 121 阅读 · 0 评论 -
LeetCode-171.Excel Sheet Colunm Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> ...原创 2018-10-24 22:43:01 · 179 阅读 · 0 评论 -
LeetCode-62 Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...原创 2018-10-24 21:50:15 · 148 阅读 · 0 评论 -
二分查找以及其有趣的使用
说到二分查找可能大家会想到二分查找的基本模板类似这样的: /** * 二分查找的基本实现 * 作用:对于一个已经从小到大排好序的数组找出目标元素的索引值 * 时间复杂度为O(logn) * @param nums * @param target * @return */ public static int Bina...原创 2018-10-29 19:37:45 · 895 阅读 · 0 评论 -
LeetCode-707 Design Linked List
Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is t...原创 2018-10-21 17:03:54 · 428 阅读 · 0 评论 -
LeetCode-49 Group Anagrams
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2018-10-20 10:09:06 · 122 阅读 · 0 评论 -
LeetCode-3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with...原创 2018-10-22 20:56:07 · 138 阅读 · 0 评论 -
LeetCode-141.Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 第一种解法使用快慢指针,如果有环则快慢指针终会相遇,然而要是出现哪一个指针的下一个为null时则代表该链表没有环public class Solution {...原创 2018-10-22 11:44:27 · 191 阅读 · 0 评论