随笔分类 -  LeetCode

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页
刷题
摘要:题目来源 LeetCode-279.完全平方数 题目详情 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。 给你一个整数 n ,返回和为 n 的完全平方数的 最少数量 。 完全平方数 是一个整数,其值等于另一个 阅读全文
posted @ 2021-12-21 10:13 Garrett_Wale 阅读(454) 评论(0) 推荐(0)
摘要:题目来源 LeetCode-238 除自身以外数组的乘积 题目描述 给你一个长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。 示例: 输入: [1,2,3,4] 输出: [24,1 阅读全文
posted @ 2021-12-20 10:31 Garrett_Wale 阅读(106) 评论(0) 推荐(0)
摘要:11. 盛最多水的容器 LeetCode-11 题目描述 给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) 。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳 阅读全文
posted @ 2021-10-03 09:56 Garrett_Wale 阅读(55) 评论(0) 推荐(0)
摘要:31. 下一个排列 LeetCode_31 题目描述 题解分析 相似题目 31. 下一个排列 556. 下一个更大元素 III 代码实现 class Solution { public void nextPermutation(int[] nums) { int i = nums.length - 阅读全文
posted @ 2021-04-03 20:42 Garrett_Wale 阅读(52) 评论(0) 推荐(0)
摘要:82. 删除排序链表中的重复元素 II LeetCode_82 题目描述 题解分析 解法一:复杂解法 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * Li 阅读全文
posted @ 2021-04-01 21:10 Garrett_Wale 阅读(107) 评论(0) 推荐(0)
摘要:41. 缺失的第一个正数 LeetCode_41 题目描述 题解分析 利用哈希表的思想,但是不是使用HashMap。 使用整个数组作为哈希桶,每个nums[i]的数字作为索引下标,将其置为负数表示该位置有数字。 需要注意最后返回的是n+1表示原来数组中包含所有1-n的数字。 方法一:哈希思想 cla 阅读全文
posted @ 2021-04-01 20:38 Garrett_Wale 阅读(100) 评论(0) 推荐(0)
摘要:题目来源 LeetCode_78 题目描述 给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。 解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 示例 1: 输入: nums = [1,2,3] 输出: [[],[1],[2],[1,2],[3],[ 阅读全文
posted @ 2021-03-31 20:52 Garrett_Wale 阅读(70) 评论(0) 推荐(0)
摘要:136. 只出现一次的数字 LeetCode_136 题目描述 相似题目:剑指 Offer 56 - I. 数组中数字出现的次数 代码实现 class Solution { public int singleNumber(int[] nums) { int n = nums.length; int 阅读全文
posted @ 2021-03-31 20:17 Garrett_Wale 阅读(56) 评论(0) 推荐(0)
摘要:468. 验证IP地址 LeetCode_468 题目描述 方法一:正则表达式 import java.util.regex.*; class Solution { //Ipv4的正则匹配表达式 String regIpv4 = "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0- 阅读全文
posted @ 2021-03-30 10:29 Garrett_Wale 阅读(136) 评论(0) 推荐(0)
摘要:题目来源 LeetCode_153 相似题目 33. 搜索旋转排序数组 153. 寻找旋转排序数组中的最小值 154. 寻找旋转排序数组中的最小值 II 题目描述 题解分析 解法一:二分法-思路一 这道题高效的解法就是二分法,利用旋转数组部分有序的性质找到最小值。 首先考虑一种情况:数组未旋转或者旋 阅读全文
posted @ 2021-03-30 09:41 Garrett_Wale 阅读(172) 评论(0) 推荐(0)
摘要:题目来源 LeetCode_34 题目描述 题解分析 解法一:二分法 这里与传统的二分法不同,这里需要找到指定元素的左右边界,所以我们无法直接套用二分法的模板。 其实,我们可以分别考虑这两种情况,与普通的二分法不同,当需要找左边界时,当我们找到target == nums[mid],我们不是直接返回 阅读全文
posted @ 2021-03-28 22:20 Garrett_Wale 阅读(65) 评论(0) 推荐(0)
摘要:48. 旋转图像 LeetCode_48 题目描述 方法一:使用辅助数组 class Solution { public void rotate(int[][] matrix) { //第i,j的元素翻转后出现在倒数第i列的第j个元素 int m = matrix.length; int n = m 阅读全文
posted @ 2021-03-28 21:37 Garrett_Wale 阅读(73) 评论(0) 推荐(0)
摘要:143. 重排链表 LeetCode_143 题目描述 代码实现 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * List 阅读全文
posted @ 2021-03-27 21:24 Garrett_Wale 阅读(61) 评论(0) 推荐(0)
摘要:143. 重排链表 LeetCode_143 题目描述 题解分析 本题的解题核心是需要找到原链表的中间节点,然后将中间节点之后的链表进行反转。 如何找到中间节点呢?这里可以使用快慢指针的思想,通过设置slow和fast指针,当fast走到尾结点时,slow指针敲好指向中间节点。 这里的反转链表操作比 阅读全文
posted @ 2021-03-27 21:22 Garrett_Wale 阅读(63) 评论(0) 推荐(0)
摘要:19. 删除链表的倒数第 N 个结点 LeetCode_19 题目描述 代码实现 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() { 阅读全文
posted @ 2021-03-27 20:57 Garrett_Wale 阅读(61) 评论(0) 推荐(0)
摘要:739. 每日温度 LeetCode_739 相似题目:单调栈结构(进阶) 题目描述 代码实现 class Solution { public int[] dailyTemperatures(int[] T) { int n = T.length; Stack<Integer> sta = new 阅读全文
posted @ 2021-03-26 21:44 Garrett_Wale 阅读(39) 评论(0) 推荐(0)
摘要:739. 每日温度 LeetCode_739 相似题目:单调栈结构(进阶) 题目描述 代码实现 class Solution { public int[] dailyTemperatures(int[] T) { int n = T.length; Stack<Integer> sta = new 阅读全文
posted @ 2021-03-26 21:42 Garrett_Wale 阅读(40) 评论(0) 推荐(0)
摘要:101. 对称二叉树 LeetCode_101 题目描述 方法一:递归法 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; 阅读全文
posted @ 2021-03-25 19:21 Garrett_Wale 阅读(41) 评论(0) 推荐(0)
摘要:题目来源 LeetCode_226 题目描述 给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。 示例 1: 输入: root = [4,2,7,1,3,6,9] 输出: [4,7,2,9,6,3,1] 示例 2: 输入: root = [2,1,3] 输出: [2,3,1] 示例 阅读全文
posted @ 2021-03-25 16:11 Garrett_Wale 阅读(101) 评论(0) 推荐(0)
摘要:98. 验证二叉搜索树 LeetCode_98 题目描述 题解分析 为每棵树都维护一个最小值和最大值,要求树的所有节点都符合边界值的要求。 需要注意的一点就是需要使用long类型的最小值和最大值。 代码实现 /** * Definition for a binary tree node. * pub 阅读全文
posted @ 2021-03-22 20:02 Garrett_Wale 阅读(37) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页