摘要: 1.力扣300--最长递增子序列 class Solution { public int lengthOfLIS(int[] nums) { //贪心算法,基本思路:dp数组维护长度为下表i的最长子序列的最后一个值的最小数 int n = nums.length; int[] dp = new in 阅读全文
posted @ 2023-01-23 11:49 lyjps 阅读(17) 评论(0) 推荐(0)
摘要: 1.力扣287--寻找重复数 class Solution { //环形链表2的变形:数组游标是指针,数组中的元素值是该节点指向下一个节点的指针 //该问题可以转化为找到环的入口 public int findDuplicate(int[] nums) { int fast = nums[0], s 阅读全文
posted @ 2023-01-23 11:48 lyjps 阅读(20) 评论(0) 推荐(0)
摘要: 1.acwing842--排列数字 import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main { public sta 阅读全文
posted @ 2023-01-20 11:47 lyjps 阅读(18) 评论(0) 推荐(0)
摘要: 1.力扣236--二叉树的最近公共祖先 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null){ return root; } // 阅读全文
posted @ 2023-01-18 16:15 lyjps 阅读(17) 评论(0) 推荐(0)
摘要: 1.实现Trie class Trie { public int[][] edges; public int cnt; public boolean[] child; public Trie() { //edges用来存节点的边 edges = new int[300010][26]; //cnt用 阅读全文
posted @ 2023-01-17 14:20 lyjps 阅读(16) 评论(0) 推荐(0)
摘要: 1.力扣200--岛屿数量 class Solution { //深度优先遍历 public int cnt; public char[][] nums; public int[] dx,dy; public int m,n; public int numIslands(char[][] grid) 阅读全文
posted @ 2023-01-16 12:28 lyjps 阅读(21) 评论(0) 推荐(0)
摘要: 1.力扣198--打家劫舍 class Solution { public int rob(int[] nums) { int n = nums.length; int[] dp = new int[n+1]; dp[0] = 0; dp[1] = nums[0]; //状态转移: //遍历到第i个 阅读全文
posted @ 2023-01-15 12:15 lyjps 阅读(22) 评论(0) 推荐(0)
摘要: 1.力扣435--无重叠区间 class Solution { public int eraseOverlapIntervals(int[][] intervals) { Arrays.sort(intervals,(o1,o2)->(o1[1]-o2[1])); int res = 1; int 阅读全文
posted @ 2023-01-14 14:55 lyjps 阅读(11) 评论(0) 推荐(0)
摘要: 1.力扣88--合并两个有序数组 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int cur = m+n-1; int p = m-1,q = n-1; while(p>=0&&q>=0){ 阅读全文
posted @ 2023-01-14 13:18 lyjps 阅读(14) 评论(0) 推荐(0)
摘要: 1.力扣148--排序链表 class Solution { //迭代法的递归排序,时间复杂度为o(1) public ListNode sortList(ListNode head) { int n = 0; ListNode l = head, r = head; //遍历整个人链表,计算节点的 阅读全文
posted @ 2023-01-12 15:06 lyjps 阅读(21) 评论(0) 推荐(0)