07 2020 档案

摘要:https://blog.csdn.net/hejingyuan6/article/details/36203505 阅读全文
posted @ 2020-07-31 17:41 浅滩浅 阅读(57) 评论(0) 推荐(0)
摘要:#饿汉式 public class Singleton{ public final static INSTANCE = new Singleton(); private Singleton(){ } } /*枚举类型限制对象个数,当我们只写一个就变成了单例模式 */ public enum Sing 阅读全文
posted @ 2020-07-31 17:00 浅滩浅 阅读(89) 评论(0) 推荐(0)
摘要:##暴力题解:双重for循环,时间复杂度O(n^2) class Solution { public int max(int a,int b){ if(a>=b) return a; return b; } public int min(int a,int b){ if(a>=b) return b 阅读全文
posted @ 2020-07-31 16:14 浅滩浅 阅读(182) 评论(0) 推荐(0)
摘要:题目链接:https://leetcode-cn.com/problems/magic-index-lcci/ 间接跳跃查找(leetcode给的测试好像都是递增的) class Solution { public int findMagicIndex(int[] nums) { for(int i 阅读全文
posted @ 2020-07-31 14:57 浅滩浅 阅读(125) 评论(0) 推荐(0)
摘要:#问题描述 Serling公司购买长钢条,将其切割为短钢条出售。切割工序本身没有成本支出。公司管理层希望知道最佳的切割方案。 假定我们知道Serling公司出售一段长为i英寸的钢条的价格为pi(i=1,2,…,单位为美元)。钢条的长度均为整英寸。 长度i 1 2 3 4 5 6 7 8 9 10 价 阅读全文
posted @ 2020-07-29 23:12 浅滩浅 阅读(252) 评论(0) 推荐(0)
摘要:以.进行分割,逐一进行转义//. ,之后数字进行比较就ok了 class Solution { public int compareVersion(String version1, String version2) { String [] v1 = version1.split("\\.");//. 阅读全文
posted @ 2020-07-29 21:55 浅滩浅 阅读(198) 评论(0) 推荐(0)
摘要:深度优先 class Solution { public boolean exist(char[][] board, String word) { char[] words = word.toCharArray(); int m = words.length; boolean[][] visit = 阅读全文
posted @ 2020-07-29 14:52 浅滩浅 阅读(99) 评论(0) 推荐(0)
摘要:深度优先搜索:将问题划分为,邻近的四个方向格子所能到达的格子数+1,由于又是从0,0开始的所以只用右、下两个方向的邻近格子就行了。 class Solution { boolean[][] visited; public int movingCount(int m, int n, int k) { 阅读全文
posted @ 2020-07-29 13:36 浅滩浅 阅读(120) 评论(0) 推荐(0)
摘要:深入理解HTTPS工作原理: https://segmentfault.com/a/1190000018992153 阅读全文
posted @ 2020-07-28 21:01 浅滩浅 阅读(115) 评论(0) 推荐(0)
摘要:class Solution { List<String> res = new LinkedList<>(); public List<String> generateParenthesis(int n) { if(n == 0) return null; dfs("",0,0,n); return 阅读全文
posted @ 2020-07-28 17:48 浅滩浅 阅读(87) 评论(0) 推荐(0)
摘要:题目链接:https://leetcode-cn.com/problems/single-number/submissions/ 要求O(1)的空间复杂度,不用排序。 动画演示: class Solution { //位运算(异或) public int singleNumber(int[] num 阅读全文
posted @ 2020-07-27 16:11 浅滩浅 阅读(67) 评论(0) 推荐(0)
摘要:class Solution { //全排列问题 Set<List<Character>> res = new HashSet<>(); public String[] permutation(String s) { char []strs = s.toCharArray(); int len = 阅读全文
posted @ 2020-07-26 19:29 浅滩浅 阅读(91) 评论(0) 推荐(0)
摘要:排序: class Solution { public boolean isStraight(int[] nums) { Arrays.sort(nums); int zero = 0; int needZero = 0; if(nums[0] == 0) zero++; for(int i=1;i 阅读全文
posted @ 2020-07-25 16:13 浅滩浅 阅读(232) 评论(0) 推荐(0)
摘要:题解:利用String数组自定义排序(字符拼接进行比较),之前还想着全排序。。。。。。。。。 class Solution { public String minNumber(int[] nums) { String []arr = new String[nums.length]; for(int 阅读全文
posted @ 2020-07-24 19:07 浅滩浅 阅读(80) 评论(0) 推荐(0)
摘要:class Solution { public int lastRemaining(int n, int m) { //模拟法超时 int pos = 0;//长度为1时候安全的下标 //反推的过程 //从i-1个人到i人的安全序号的变化 //正过程: //1、下标为j+1的成为数组头,j前面的人加 阅读全文
posted @ 2020-07-24 18:17 浅滩浅 阅读(105) 评论(0) 推荐(0)
摘要:思路:用一个栈进行模拟,当栈不为空且栈顶元素与出栈数组的元素相等时,元素出栈,出栈元素后移,继续与栈顶元素对比,如此反复 class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { Stac 阅读全文
posted @ 2020-07-23 21:51 浅滩浅 阅读(109) 评论(0) 推荐(0)
摘要:解题:前序遍历加上筛选 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = 阅读全文
posted @ 2020-07-23 20:23 浅滩浅 阅读(135) 评论(0) 推荐(0)
摘要:平衡树:对于每一个节点它的左右子树深度差不能超过1 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode( 阅读全文
posted @ 2020-07-23 19:12 浅滩浅 阅读(107) 评论(0) 推荐(0)
摘要:二叉搜索树:左子树的值小于右子树的值(不会出现重复的情况) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN 阅读全文
posted @ 2020-07-23 18:23 浅滩浅 阅读(112) 评论(0) 推荐(0)
摘要:思路:后序遍历 分情况讨论: 1、两个节点在根的左侧 2、两个节点在根的右侧 3、两个节点在根的左右两侧 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * 阅读全文
posted @ 2020-07-23 17:52 浅滩浅 阅读(124) 评论(0) 推荐(0)
摘要:题解:用一位数代替标记数组节省空间 class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> permute(int[] nums) { List<Integer> list = 阅读全文
posted @ 2020-07-22 18:06 浅滩浅 阅读(114) 评论(0) 推荐(0)
摘要:转为字符串分情况讨论 class Solution { public int reverse(int x) { long num = 0; String numStr = x + ""; int len = numStr.length(); if(x >= 0){ for(int i=len-1;i 阅读全文
posted @ 2020-07-20 12:27 浅滩浅 阅读(121) 评论(0) 推荐(0)
摘要:1、没利用完全二叉树性质的递归 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { v 阅读全文
posted @ 2020-07-19 11:16 浅滩浅 阅读(697) 评论(0) 推荐(0)
摘要:1、递归后序遍历 class Solution { public int maxDepth(TreeNode root) { if(root == null) return 0; return Math.max(maxDepth(root.left), maxDepth(root.right)) + 阅读全文
posted @ 2020-07-19 10:38 浅滩浅 阅读(134) 评论(0) 推荐(0)
摘要:题解:层次遍历的基础上加个计数器,偶数层得到的结果反转一下 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN 阅读全文
posted @ 2020-07-18 18:42 浅滩浅 阅读(78) 评论(0) 推荐(0)
摘要:还是层次遍历返回值类型不同罢了 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { v 阅读全文
posted @ 2020-07-18 18:29 浅滩浅 阅读(76) 评论(0) 推荐(0)
摘要:解题:利用队列先进先出来实现层次遍历 因为需要按层次遍历节点,所以我们可以使用队列先进先出的特点来存储每层节点的值 每取出一个节点就将该节点的左右节点存入队列当中 /** * Definition for a binary tree node. * public class TreeNode { * 阅读全文
posted @ 2020-07-18 16:54 浅滩浅 阅读(98) 评论(0) 推荐(0)
摘要:思路: 镜像前序遍历和本体前序遍历是否相同 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int 阅读全文
posted @ 2020-07-18 16:06 浅滩浅 阅读(93) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-07-18 14:52 浅滩浅 阅读(71) 评论(0) 推荐(0)
摘要:class Solution { public int findLengthOfLCIS(int[] nums) { int n=nums.length; if(n==0) return 0; int res=1; int []f=new int[n]; //f[i]截止到扫描到i最长升序长度 f[ 阅读全文
posted @ 2020-07-18 12:53 浅滩浅 阅读(139) 评论(0) 推荐(0)
摘要:题解:双指针 快指针一次两步,慢指针一次一步,当快指针走到结尾时候慢指针刚好到终点 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(in 阅读全文
posted @ 2020-07-18 09:46 浅滩浅 阅读(125) 评论(0) 推荐(0)
摘要:##题解:hashset(没有达到进阶的要求) /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next 阅读全文
posted @ 2020-07-18 09:31 浅滩浅 阅读(188) 评论(0) 推荐(0)
摘要:题解:双指针 一个指针一次移动2步,一个指针一次移动一步。如果两个指针相遇证明存在环. /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) 阅读全文
posted @ 2020-07-18 08:51 浅滩浅 阅读(111) 评论(0) 推荐(0)
摘要:class Solution { public int lengthOfLongestSubstring(String s) { if(s.length()==0) return 0; //双指针(r指针最先向右移动,遇到重复的l指针向右移动直到越过重复的r指针继续向右移动) int l=0,r=0 阅读全文
posted @ 2020-07-18 07:44 浅滩浅 阅读(281) 评论(0) 推荐(0)
摘要:class Solution { public int searchInsert(int[] nums, int target) { int len=nums.length; int l=0,r=len-1,ans=len; while(l<=r){ int mid = (r+l)/2; if(nu 阅读全文
posted @ 2020-07-17 14:51 浅滩浅 阅读(113) 评论(0) 推荐(0)
摘要:class Solution { Stack<Character> stk = new Stack<>(); public boolean isValid(String s) { int len=s.length(); for(int i=0;i<len;i++){ char ch = s.char 阅读全文
posted @ 2020-07-17 14:48 浅滩浅 阅读(107) 评论(0) 推荐(0)
摘要:二分找左右边界 class Solution { public int search(int[] nums, int target) { int start=findLeft(nums,target),end=findRight(nums,target); if(start 1||end 1) re 阅读全文
posted @ 2020-07-17 11:08 浅滩浅 阅读(307) 评论(0) 推荐(0)
摘要:解题:利用二分找到一个相等的元素,之后再左右边界 class Solution { public int[] searchRange(int[] nums, int target) { int n=nums.length; int l=0,r=n-1; int start=-1,end=-1; wh 阅读全文
posted @ 2020-07-17 10:08 浅滩浅 阅读(193) 评论(0) 推荐(0)
摘要:思路 $假设x_1x_2....x_{i-2}的翻译方式为f(i-2)种$ \(假设x_1x_2....x_{i-2}x_{i-1}的翻译方式为f(i-1)种\) \(可以得出x_1x_2....x_{i-2}x_{i-1}x_i的翻译方式\) 1.\(x_{i-1}和xi可以组合翻译那就可以选择组 阅读全文
posted @ 2020-07-15 21:20 浅滩浅 阅读(188) 评论(0) 推荐(0)
摘要:这道题目我之前做过就不多解释了:https://www.cnblogs.com/cstdio1/p/13072712.html /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNo 阅读全文
posted @ 2020-07-15 19:22 浅滩浅 阅读(111) 评论(0) 推荐(0)
摘要:class Solution { public int[] singleNumbers(int[] nums) { Set<Integer> set = new HashSet<>(); int n = nums.length; for(int i=0;i<n;i++){ if(set.contai 阅读全文
posted @ 2020-07-15 19:12 浅滩浅 阅读(121) 评论(0) 推荐(0)
摘要:思路:排序+分情况 class Solution { public int singleNumber(int[] nums) { Arrays.sort(nums); int len=nums.length; for(int i=1;i<len-1;i++){ if(nums[i]!=nums[i- 阅读全文
posted @ 2020-07-15 18:51 浅滩浅 阅读(117) 评论(0) 推荐(0)
摘要:解法:分情况:1、缺开头。 2、缺的元素在中间部位。 3、缺的元素在最后一个位置。 class Solution { public int missingNumber(int[] nums) { int len=nums.length; for(int i=1;i<len;i++){ if(nums 阅读全文
posted @ 2020-07-15 18:21 浅滩浅 阅读(236) 评论(0) 推荐(0)
摘要:经典dp问题 class Solution { public int maxValue(int[][] grid) { int m=grid.length,n=grid[0].length; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(i==0&&j 阅读全文
posted @ 2020-07-15 13:44 浅滩浅 阅读(108) 评论(0) 推荐(0)
摘要:##我的题解 /* // Definition for a Node. class Node { int val; Node next; Node random; public Node(int val) { this.val = val; this.next = null; this.random 阅读全文
posted @ 2020-07-14 20:03 浅滩浅 阅读(106) 评论(0) 推荐(0)
摘要:class Solution { List<List<Integer>> res = new LinkedList<>(); List<Integer> list = new LinkedList<>(); void backtrack(int[] nums, LinkedList<Integer> 阅读全文
posted @ 2020-07-14 18:06 浅滩浅 阅读(203) 评论(0) 推荐(0)
摘要:class Solution { public int removeDuplicates(int[] nums) { int cnt=0; int len=nums.length; for(int i=1;i<len;i++){ if(nums[i]==nums[i-1]){ for(int j=i 阅读全文
posted @ 2020-07-14 11:04 浅滩浅 阅读(118) 评论(0) 推荐(0)
摘要:class Solution { public int minimumTotal(List<List<Integer>> triangle) { int height = triangle.size(),width=0; int [][]dp = new int[height][]; for(int 阅读全文
posted @ 2020-07-14 10:28 浅滩浅 阅读(188) 评论(0) 推荐(0)
摘要:解题:这个好像是某年考研题,大概思路就是先遍历链表用一个计数器++,当计数值=k时,再用一个指针遍历链表,两个遍历相差k位,当第一个链表遍历完了,第二个链表遍历到倒数第k个元素。 举例:一个人先跑距离为k,另一个人开始起跑,当第一个人到终点时第二个人距离终点距离为k 代码 /** * Definit 阅读全文
posted @ 2020-07-13 21:45 浅滩浅 阅读(122) 评论(0) 推荐(0)
摘要:代码 由于这个链表的头结点也是数据部分,为了保持删除操作的一致性在头结点前面加上一个扩展头节点指向数据头节点。 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; 阅读全文
posted @ 2020-07-13 21:24 浅滩浅 阅读(176) 评论(0) 推荐(0)
摘要:股票1(只买卖1次) 注意:这个不仅仅是找到数组最大最小就行了,注意时间顺序 class Solution { public int maxProfit(int[] prices) { if(prices.length==0||prices==null) return 0; int max=0,mi 阅读全文
posted @ 2020-07-13 17:57 浅滩浅 阅读(158) 评论(0) 推荐(0)
摘要:题解 nums[i]为最左端的数,nums[L]为中间,nums[R]为最右端数, 最外层循环遍历最左端,nums[L]最初指向nuns[i+1],nums[R]最初指向nums[nums.length-1],根据sum变化不断移动 代码 class Solution { public static 阅读全文
posted @ 2020-07-12 15:30 浅滩浅 阅读(259) 评论(0) 推荐(0)
摘要:代码: class Solution { public double myPow(double x, int n) { int len = Math.abs(n); if(len==0) return 1; if(len==1){ if(n>0) return x; return 1/x; } if 阅读全文
posted @ 2020-07-08 13:11 浅滩浅 阅读(188) 评论(0) 推荐(0)