随笔分类 -  top100

摘要:public ListNode deleteDuplicates (ListNode head) { // write code here ListNode cur=head; while(cur!=null){ while(cur.next!=null&&cur.val==cur.next.val 阅读全文
posted @ 2023-11-22 21:55 Chenyi_li 阅读(2) 评论(0) 推荐(0) 编辑
摘要:链表逆置 public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @return ListNode类 */ public ListNode ReverseList 阅读全文
posted @ 2023-11-22 16:24 Chenyi_li 阅读(2) 评论(0) 推荐(0) 编辑
摘要:层次遍历 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int v 阅读全文
posted @ 2023-11-22 11:46 Chenyi_li 阅读(1) 评论(0) 推荐(0) 编辑
摘要:快速排序 package jh; public class QuickSort { public static int partition(int[] array,int start,int end){ int base = array[start]; while (start < end){ // 阅读全文
posted @ 2023-11-21 22:47 Chenyi_li 阅读(5) 评论(0) 推荐(0) 编辑
摘要:方法1:直接用数组排序 public class StringSort { public static void main(String[] args) { String[] strings = {"abc123", "abc+1234", "ababab--1"}; // 对每个字符串计算字母字符 阅读全文
posted @ 2023-10-06 14:43 Chenyi_li 阅读(48) 评论(0) 推荐(0) 编辑
摘要:class Solution { public boolean canPartition(int[] nums) { int len = nums.length; // 题目已经说非空数组,可以不做非空判断 int sum = 0; for (int num : nums) { sum += num 阅读全文
posted @ 2023-09-25 21:41 Chenyi_li 阅读(3) 评论(0) 推荐(0) 编辑
摘要:https://programmercarl.com/背包理论基础01背包-1.html#总结 https://www.bilibili.com/video/BV1C7411K79w?p=1&vd_source=46d50b5d646b50dcb2a208d3946b1598 package dyn 阅读全文
posted @ 2023-09-25 21:12 Chenyi_li 阅读(5) 评论(0) 推荐(0) 编辑
摘要:// 1.从数组中找出第三大的数,例如{10,10,9,9,8,8,7,7} 第三大的数是8 414. 第三大的数 public class ThirdLargestNumber { public static void main(String[] args) { int[] nums = {10, 阅读全文
posted @ 2023-09-11 21:46 Chenyi_li 阅读(183) 评论(0) 推荐(0) 编辑
摘要:要求长度为 k 的连续子数组的最大和,可以使用滑动窗口的方法来解决。具体步骤如下: ``` public int findMaxSum(int[] nums, int k) { int maxSum = 0; // 最大和 int currSum = 0; // 当前窗口的和 // 第一个窗口的求和 阅读全文
posted @ 2023-08-29 21:29 Chenyi_li 阅读(56) 评论(0) 推荐(0) 编辑
摘要:给定一个升序排列的的长度为n的数组nums,数组中每个元素都是正整数,请删除一部分这个数组的重复元素(数组元素需要原地改变),让这个数组中的每个数字都严格大于前一个数(第一个数除外),然后返回删除过后该数组的长度。例如n=4,nums=[1,2,2,3],则输出3.java代码实现 ``` publ 阅读全文
posted @ 2023-08-29 21:22 Chenyi_li 阅读(14) 评论(0) 推荐(0) 编辑
摘要:[LCR 026. 重排链表](https://leetcode.cn/problems/LGjMqU/description/) ``` /** * Definition for singly-linked list. * public class ListNode { * int val; * 阅读全文
posted @ 2023-08-18 20:31 Chenyi_li 阅读(9) 评论(0) 推荐(0) 编辑
摘要:[662. 二叉树最大宽度](https://leetcode.cn/problems/maximum-width-of-binary-tree/description/) ## BFS ,也就是广度优先遍历,类似层次遍历的方法(同上给每个节点编上号),求得每一层,把每一层的左右两端的编号进行相减。 阅读全文
posted @ 2023-08-18 16:26 Chenyi_li 阅读(7) 评论(0) 推荐(0) 编辑
摘要:[73.矩阵置零](https://leetcode.cn/problems/set-matrix-zeroes/solutions/6594/o1kong-jian-by-powcai/?envType=study-plan-v2&envId=top-100-liked) 思路: 思路一: 用 O 阅读全文
posted @ 2023-08-16 19:55 Chenyi_li 阅读(47) 评论(0) 推荐(0) 编辑
摘要:[240. 搜索二维矩阵 II](https://leetcode.cn/problems/search-a-2d-matrix-ii/solutions/2361487/240-sou-suo-er-wei-ju-zhen-iitan-xin-qin-7mtf/?envType=study-pla 阅读全文
posted @ 2023-08-16 14:46 Chenyi_li 阅读(3) 评论(0) 推荐(0) 编辑
摘要:[54. 螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/description/?envType=study-plan-v2&envId=top-100-liked) ``` class Solution { public List spiralO 阅读全文
posted @ 2023-08-14 22:05 Chenyi_li 阅读(6) 评论(0) 推荐(0) 编辑
摘要:1.暴力法的优化 子循环中记录和 class Solution { public int subarraySum(int[] nums, int k) { int count = 0; for(int i=0; i<nums.length; i++){ int sum=0; for(int j=i; 阅读全文
posted @ 2023-08-13 16:23 Chenyi_li 阅读(5) 评论(0) 推荐(0) 编辑
摘要:![](https://img2023.cnblogs.com/blog/1892439/202308/1892439-20230812214348694-366989869.png) ![](https://img2023.cnblogs.com/blog/1892439/202308/18924 阅读全文
posted @ 2023-08-12 21:51 Chenyi_li 阅读(5) 评论(0) 推荐(0) 编辑
摘要:解题思路: 我们要知道,饼干数决定喂饱的孩子的数,所以我们以饼干数做循环。 先将两个数组进行排序(sort),【贪心算法就是在每一步选择最优解,即最小的饼干要给满足度最小的孩子,才能达到最大化的价值】, 定义结果为res。 我们创建两个指针(i,j) i指向第一个孩子,j指向第一个饼干,出现的情况: 阅读全文
posted @ 2023-08-05 10:20 Chenyi_li 阅读(2) 评论(0) 推荐(0) 编辑
摘要:[剑指 Offer 42. 连续子数组的最大和](https://leetcode.cn/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/description/) ``` class Solution { public int maxSubArray(in 阅读全文
posted @ 2023-08-04 15:09 Chenyi_li 阅读(6) 评论(0) 推荐(0) 编辑
摘要:[剑指 Offer 34. 二叉树中和为某一值的路径](https://leetcode.cn/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/description/) ## 1.先写一种错误的写法,这是自己第一次写的写法 ` 阅读全文
posted @ 2023-08-04 11:11 Chenyi_li 阅读(5) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示