自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(31)
  • 收藏
  • 关注

原创 【无标题】力扣旋转链表

2022-07-28 15:24:31 98 1

原创 每日一题:粉刷房子

class Solution { public int minCost(int[][] costs) { int n = costs.length; int[][] dp = new int[n][3]; dp[0][0] = costs[0][0]; dp[0][1] = costs[0][1]; dp[0][2] = costs[0][2]; for(int i = 1;i < n;i++){ dp[i][0]...

2022-06-25 20:00:47 78

原创 典中典两数之和

class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { if(l1 == null && l2 == null){ return null; } if(l1 != null && l2 == null){ return l1; } if(l2 != null && l1 == null){...

2022-06-24 15:12:34 78

原创 力扣跳跃游戏,贪心

class Solution { public int jump(int[] nums) { int n = nums.length; if(n == 1){ return 0; } int max = nums[0]; if(max >= n - 1){ return 1; } int temp = max; int count = 1; for(int i = 1;i <= max...

2022-06-20 14:45:47 487

原创 力扣排序的循环链表

class Solution { public Node insert(Node head, int insertVal) { Node root = new Node(insertVal); if(head == null){ root.next = root; return root; } if(head.next == head){ root....

2022-06-18 15:17:36 86

原创 力扣复原ip

class Solution { List<String> list; int[] arr; int n; public List<String> restoreIpAddresses(String s) { list = new ArrayList<>(); arr = new int[4]; n = s.length(); if(n < 4){ return lis...

2022-06-13 15:49:30 50

原创 力扣不同二叉搜索树||

class Solution { List<TreeNode> list; public List<TreeNode> generateTrees(int n) { list = new ArrayList<>(); return dfs(1,n); } List<TreeNode> dfs(int l,int r){ List<TreeNode> arr = new Arr...

2022-06-03 15:30:04 46

原创 力扣每日一题

class Solution { List<TreeNode> list; Map<TreeNode,TreeNode> map; public TreeNode deleteNode(TreeNode root, int key) { if(root == null){ return null; } if(root.val == key && root.left == null &...

2022-06-02 15:32:48 51

原创 力扣相同二叉树

class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null){ return true; } if((p == null && q != null) || (p != null && q == null)){ return false; } ...

2022-05-31 15:06:19 42

原创 力扣重建二叉树

class Solution { int n; public TreeNode buildTree(int[] preorder, int[] inorder) { n = preorder.length; if(n == 0){ return null; } return dfs(preorder,inorder,0,n - 1,0,n - 1); } TreeNode dfs(int[] pre,int[] ino,i...

2022-05-30 16:04:08 56

原创 今日份每日一题

class Solution { public int findClosest(String[] words, String word1, String word2) { int n = words.length; List<Integer> list1 = new ArrayList<>(); List<Integer> list2 = new ArrayList<>(); int min = Intege...

2022-05-27 15:47:41 55

原创 力扣最大连续子数组乘积

class Solution { public int maxProduct(int[] nums) { int n = nums.length; int[] max = new int[n]; int[] min = new int[n]; max[0] = nums[0]; min[0] = nums[0]; int count = nums[0]; for(int i = 1;i < n;i++){ ...

2022-05-26 16:12:21 95

原创 力扣所有子集

class Solution { List<List<Integer>> list; List<Integer> ans; int n; public List<List<Integer>> subsets(int[] nums) { list = new ArrayList<>(); ans = new ArrayList<>(); n = nums.length;...

2022-05-21 14:24:38 62

原创 力扣二分查找

class Solution { public int[] searchRange(int[] nums, int target) { int n = nums.length; int l = 0,r = n - 1; while(l <= r){ int mid = l + (r - l) / 2; if(nums[mid] == target){ int[] arr = new int[2]; ...

2022-05-19 14:53:58 70

原创 今日每日一题

class Solution { public boolean isAlienSorted(String[] words, String order) { int n = words.length; int len = order.length(); Map<Character,Integer> map = new HashMap<>(); for(int i = 0;i < len;i++){ map.put(order...

2022-05-17 14:47:38 36

原创 力扣数组全排列

class Solution { List<List<Integer>> list; List<Integer> ans; int n; public List<List<Integer>> subsets(int[] nums) { list = new ArrayList<>(); ans = new ArrayList<>(); this.n = n...

2022-05-16 14:46:35 55

原创 力扣最大盛水量

class Solution { public int maxArea(int[] height) { int n = height.length; int l = 0; int r = n - 1; int max = Math.min(height[l],height[r]) *(r - l); while(l < r){ while(height[l] <= height[r] && l < r){ ...

2022-05-15 14:45:59 67

原创 力扣换硬币,动态规划

class Solution { public int coinChange(int[] coins, int amount) { int n = coins.length; int[] dp = new int[amount + 1]; Arrays.fill(dp,amount + 1); dp[0] = 0; for(int i = 0;i < amount + 1;i++){ for(int j : coins){...

2022-05-14 20:31:54 79

原创 每日一题:一次编辑

class Solution { public boolean oneEditAway(String first, String second) { if(first.equals(second)){ return true; } int n = first.length(); int m = second.length(); if((n == 0 && m == 1) || (n == 1 && ...

2022-05-13 14:34:29 80

原创 力扣任务调度器

class Solution { public int leastInterval(char[] tasks, int n) { int len = tasks.length; int[] arr = new int[26]; for(char c : tasks){ ++arr[c - 'A']; } Arrays.sort(arr); int max = arr[25]; int num = 0; int coun...

2022-05-12 22:02:53 114

原创 二叉树的根节点到叶子节点相加为某一值

class Solution { List<List<Integer>> list; List<Integer> ans; public List<List<Integer>> pathSum(TreeNode root, int targetSum) { list = new ArrayList<>(); ans = new ArrayList<>(); if(r...

2022-05-11 14:55:18 81

原创 力扣一个数的最大乘积

class Solution { public int integerBreak(int n) { int[] dp = new int[n + 1]; dp[0] = 0; dp[1] = 1; for(int i = 2;i < n + 1;i++){ for(int j = 0;j < i;j++){ dp[i] = Math.max(dp[j] * (i - j),Math.max(dp[i],j * (i ...

2022-05-10 15:33:53 47

原创 力扣之兑换硬币,动态规划

class Solution { public int coinChange(int[] coins, int amount) { int n = coins.length; int[] arr = new int[amount + 1]; Arrays.fill(arr,amount + 1); arr[0] = 0; for(int i = 1;i <= amount;i++){ for(int j = 0;j < n;j++)...

2022-05-10 15:06:57 212

原创 力扣切割回文子串

class Solution { List<List<String>> list; List<String> ans; int n = 0; boolean[][] dp; public List<List<String>> partition(String s) { list = new ArrayList<>(); ans = new ArrayList<&...

2022-05-07 16:04:15 130

原创 今日份力扣每日一题,转圈圈

class Solution { List<Integer> list; public int findTheWinner(int n, int k) { list = new ArrayList<>(); for(int i = 1;i <= n;i++){ list.add(i); } dfs(list,k,0); return list.get(0); } void dfs...

2022-05-04 14:45:47 41

原创 力扣的每日一题,今天这个简单题不太简单,主要是排序方法细节很多,我发现,只有带图片才会有阅读量

class Solution { public String[] reorderLogFiles(String[] logs) { int n = logs.length; List<String> list = new ArrayList<>(); List<String> digit = new ArrayList<>(); for(String s : logs){ String[] str = ...

2022-05-03 21:04:10 85

原创 最折磨人的还是字符串题:力扣字符串转int

class Solution { public int myAtoi(String s) { StringBuffer st = new StringBuffer(); int j = 0; while(j < s.length() && s.charAt(j) == ' '){ j++; } for(int i = j;i < s.length();i++){ st.append(s....

2022-04-30 15:06:21 65

原创 二叉树中序遍历的迭代法

/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val = val; }* TreeNode(int val, TreeNode left, TreeNode right) {*...

2022-04-29 16:03:38 680

原创 索引的设计原则

1.经常用于查询的字段2.用于缩小查询范围的字段3.用于排序(order by )的字段4.使用最左前缀原则5.设置索引的字段区分度要大,比如性别字段,就不适合建立索引6.设置索引的字段不宜过长,因为索引也会占用空间7.索引不宜建立过多,因为每次增删数据,都要维护索引...

2022-04-29 00:21:32 207

原创 力扣全排列代码核心部分讲解

class Solution {本题是比较常规的回溯问题,其中的一个需要解决的点是如何去重,本文主要针对去重做一下讲解 List<List<Integer>> list; List<Integer> ans; int n;建立一个boolean型数组,用来记录该位置的数据是否已经被使用,true表示已经被使用,false相反,以防止同一个数据被使用两次。 boolean[] flag; public List<List...

2022-04-27 22:02:42 164

原创 分享一下力扣动态规划题,买卖股票含冷冻期

class Solution { public int maxProfit(int[] prices) { int n = prices.length; int[][] dp = new int[n][3]; dp[0][0] = -prices[0]; dp[0][1] = 0; dp[0][2] = 0; for(int i = 1;i < n;i++){ dp[i][0] = Math.max(dp[i - 1][0],dp...

2022-04-27 00:29:11 1252

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除