- 博客(38)
- 收藏
- 关注
原创 Mysql幻读
Mysql幻读知识点:1.幻读一般发生在可重复读级别。2.幻读的解决办法,可通过可重复读级别下第一次读,使用select * from … for update. 或者for read 可以加间隙写锁或者读锁。3.间隙锁可看https://www.jianshu.com/p/bf862c37c4c94.mysql...
2021-03-28 16:56:24 127
原创 Mysql忘记密码跳过权限认证
Mysql忘记密码跳过权限认证1.关闭mysql2.修改mysql下的my.conf文件【mysqld】下添加skip-grant-tables3.修改root密码use mysqlupdate user set Password=password(‘123456’) where user=‘root’;flush privileges ;quit4.可尝试新打开一个cmd尝试利用密码登陆5.修改my.conf恢复原样6.重启mysql...
2021-03-28 16:19:40 225
原创 两数之和
两数之和给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。你可以按任意顺序返回答案。思路:hash表import java.util.Map;import java.util.HashMap;class Solution { public int[] twoSum(int[] nums, int target) {
2021-03-27 09:56:39 90
原创 二叉树的下一节点
二叉树的下一节点/*public class TreeLinkNode { int val; TreeLinkNode left = null; TreeLinkNode right = null; TreeLinkNode next = null; TreeLinkNode(int val) { this.val = val; }}*/public class Solution { public TreeLinkNode G
2021-03-15 18:04:44 80
原创 字符串中第一个出现的不重复的数
字符串中第一个出现的不重复的数public class Solution { //Insert one char from stringstream int[] arr = new int[128]; //记录次数 StringBuilder sb = new StringBuilder();//记录位置 public void Insert(char ch) { sb.append(ch); arr[ch]++; } /
2021-03-15 17:14:59 110
原创 扑克牌顺子
扑克牌顺子class Solution { public boolean isStraight(int[] nums) { Set<Integer> repeat = new HashSet<>(); int max = 0, min = 14; for(int num : nums) { if(num == 0) continue; // 跳过大小王 max = Math.ma
2021-03-15 16:48:33 87
原创 两个链表对应数字相加
两个链表对应数字相加/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = ne
2021-03-14 10:03:47 90
原创 有序旋转数组查找
有序旋转数组查找class Solution { public int search(int[] nums, int target) { int n = nums.length; if (n == 0) { return -1; } if (n == 1) { return nums[0] == target ? 0 : -1; } int l = 0,
2021-03-11 22:51:21 116
原创 回文数
回文数class Solution { public boolean isPalindrome(int x) { // 特殊情况: // 如上所述,当 x < 0 时,x 不是回文数。 // 同样地,如果数字的最后一位是 0,为了使该数字为回文, // 则其第一位数字也应该是 0 // 只有 0 满足这一属性 if (x < 0 || (x % 10 == 0 && x !=
2021-03-11 13:55:24 93
原创 最长公共前缀
最长公共前缀class Solution { public String longestCommonPrefix(String[] strs) { if (strs == null || strs.length == 0) { return ""; } else { return longestCommonPrefix(strs, 0, strs.length - 1); } } pu
2021-03-10 13:02:39 78
原创 快乐数
快乐数class Solution { private int getNext(int n) { int totalSum = 0; while (n > 0) { int d = n % 10; n = n / 10; totalSum += d * d; } return totalSum; } public boolean isHap
2021-03-10 12:55:21 89
原创 集合子集
标题集合子集思路针对针对cur的元素有两种办法一种是取,一种是不取。t.add() t.remove(), 继续递归。class Solution { List<Integer> t = new ArrayList<Integer>(); List<List<Integer>> ans = new ArrayList<List<Integer>>(); public List<List&
2021-03-10 09:58:29 81
原创 比较版本号
比较版本号class Solution { public int compareVersion(String version1, String version2) { String[] nums1 = version1.split("\\."); String[] nums2 = version2.split("\\."); int n1 = nums1.length, n2 = nums2.length; // compare versions int i1
2021-03-10 08:37:28 81
原创 最少跳跃数(跳跃游戏II)
最少跳跃数(II)给定一个非负整数数组,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。你的目标是使用最少的跳跃次数到达数组的最后一个位置。public int jump(int[] nums) { int position = nums.length - 1; //要找的位置 int steps = 0; while (position != 0) { //是否到了第 0 个位置 for (int i = 0; i < p
2021-03-10 08:02:28 420
原创 删除链表重复元素
删除链表重复元素题目1. 保留一个重复元素/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; t
2021-03-09 16:29:22 59
原创 字符串ip地址组合
字符串ip地址组合思路:dfs思路package com.dfs;import java.util.ArrayList;public class StringIP { public static final int segment_count = 4; public ArrayList<String> arrayList = new ArrayList<>(); public int[] segments = new int[segment_cou
2021-03-09 15:51:55 499
原创 删除链表的中间节点
删除链表的中间节点删除链表的中间节点public static LinkNode removeHalfNode(LinkNode node) { if(node==null || node.next==null) { return node; } if (node.next.next==null) { return node.next; } LinkNode fast = node.next.next; LinkNode slow = node; //重点slow指的
2021-03-06 15:51:44 115
原创 最短通路值
最短通路值package com.juzhen;import java.util.LinkedList;import java.util.Queue;//最短通路值public class ShortestPath { public static void main(String[] args) { int[][] array = {{1,0,1,1,1},{1,0,1,0,1},{1,1,1,0,1},{1,1,1,1,1}}; System.out.print(shortestP
2021-03-06 15:43:49 197 2
原创 子数组最大和
子数组最大和public static int MostSumOfZixulieMethod(int[] arrays) { if(arrays==null || arrays.length==0) { return 0; } int subsum = 0; int maxsum = Integer.MIN_VALUE; for(int i=0; i<arrays.length; i++) { if(subsum<0) { subsum = arrays
2021-03-06 15:13:57 79
原创 换线方法数
换线方法数public static int numbersOfMethodVersionTwoOfPress(int money, int[] chargeMoney) { if (money<0 || chargeMoney==null || chargeMoney.length==0) { return 0; } int[] result= new int[money+1]; //初始化只是用一种货币的情况, result[0][0]=1;
2021-03-06 15:09:14 93
原创 换钱所需要的最少钱币个数
换钱所需要的最少钱币个数public static int mostlessMoneyNumerMethodOfPress(int money, int[] chargeMoney) { if(money<0||chargeMoney==null||chargeMoney.length==0) { return 0; } //result[0...i][0] 为0 int[] result = new int[money+1]; for(int j=1;j<=mone
2021-03-06 14:56:39 101
原创 最长公共子序列
最长公共子序列package com.dynamic;//最长公共子序列public class MostLenthCommonSubXulie { //1A2C3D4B56 public static void main(String[] args) { String string1 = "1A2C3D4B56"; String string2 = "B1D23CA45B6A"; char[] arr1 = string1.toCharArray(); char[] arr
2021-03-06 14:45:07 91 1
原创 最长回文子串
最长回文子串public static String longestSubStringHuiWen(char[] stringarray, String s) { if (stringarray==null || stringarray.length == 0) { return ""; } boolean[][] dp = new boolean[stringarray.length][stringarray.length]; int len = stringarray.lengt
2021-03-06 14:38:03 80
原创 最长递增子序列
最长递增子序列package com.dynamic;//最长递增子序列不连续public class MostLengthDiZengSubXulie { public static void main(String[] args) { int[] arr = {2,5,1,4,3,6,7}; int[] result = dp(arr); result = generateLIS(arr, result); for(int i=0;i<result.length;i
2021-03-06 14:24:51 90 1
原创 最长公共子串
最长公共子串package com.dynamic;public class MostLengthCommonSubString { public static void main(String[] args) { String string1 = "12345ABCD"; String string2 = "12345EF"; System.out.print(MostLengthCommonSubStringMethod(string1, string2)); } publi
2021-03-06 14:02:45 53
原创 单词搜索
矩阵包含字符串class Solution { public boolean result=false; public boolean exist(char[][] board, String word) { int[][] visited = new int[board.length][board[0].length]; char[] a = word.toCharArray(); for(int i=0;i<board.length
2021-03-06 11:20:24 91
原创 路径总和判断是否存在到叶子结点相加等于某值
路径总和判断是否存在到叶子结点相加等于某值/** * 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
2021-03-06 11:08:13 98
原创 路径总和求出所有路径到叶子节点
路径总和求出所有路径到叶子节点给你二叉树的根节点 root 和一个整数目标和 targetSum ,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。叶子节点 是指没有子节点的节点。class Solution { List<List<Integer>> arrays = new ArrayList<List<Integer>>(); public List<List<Integer>> pathSum(
2021-03-06 10:58:40 260
原创 二叉树路径等于某个值的路径个数
二叉树路径总和个数给定一个二叉树,它的每个结点都存放着一个整数值。找出路径和等于给定数值的路径总数。路径不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点)。二叉树不超过1000个节点,且节点数值范围是 [-1000000,1000000] 的整数。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left;
2021-03-06 10:47:21 440
原创 a的b次幂
a的b次幂public static float method(int a, int b) { float res = 0.0f; if(b==0) { return 1; } if(b<0) { res = 1/method(a, -b); return res; } if(b%2==0) { res = method(a*a, b/2); return res; }else { res = method(a*a, b/2)*a;
2021-03-03 23:39:06 469 1
原创 大数相加
大数相加public static String bigNumberSum(String number1, String number2) { String num1 = new StringBuffer(number1).reverse().toString(); String num2 = new StringBuffer(number2).reverse().toString(); int num1Length = num1.length(); int num2Length = nu
2021-03-03 23:37:27 141 1
原创 两数相加
两数相加public class TwoNumberAdd { public static void main(String[] args) { int number1 = 10; int number2 = 12; while (number2!=0){ int temp = number1^number2;//no jinwei number2 = (number1&number2)<
2021-03-03 14:39:21 96 1
原创 进制转换
进制转换package com.special;import com.sun.xml.internal.ws.encoding.MtomCodec;//mpublic class NumberMToNJinzhi { public static void main(String[] args) { int m =1000; int n = 5; System.out.println(MToN(-1000, 5)); } public s
2021-03-03 14:33:39 70 1
原创 合并二叉树
合并二叉树import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param t1 TreeNode类 * @param t2 TreeNode类 * @return TreeNo
2021-03-03 14:29:15 74 1
原创 最大数
最大数import java.util.*;public class Solution { /** * 最大数 * @param nums int整型一维数组 * @return string字符串 */ public String solve (int[] nums) { // write code here ArrayList<String> list = new ArrayList<St
2021-03-03 14:28:08 105 1
原创 最长递增路径
最长递增路径import java.util.*;public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 递增路径的最大长度 * @param matrix int整型二维数组 描述矩阵的每个数 * @return int整型 */ public int maxLength; public int solve (int[][] matrix) {
2021-03-03 12:14:43 108 1
原创 链表的奇偶重排
链表的奇偶重排public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param head ListNode类 * @return ListNode类 */ public ListNode oddEvenList (ListNode head) { // write code here if(head==null||h
2021-03-03 10:49:10 263
原创 Java类型擦除
Java类型擦除泛型的本质就是“参数化类型”,也就是说所操作的数据类型被指定为一个参数。 创建集合时就指定集合元素的数据类型,该集合只能保存其指定类型的元素, 避免使用强制类型转换。 Java 编译器生成的字节码是不包含泛型信息的,泛型类型信息将在编译处理时 被擦除,这个过程即类型擦除。类型擦除可以简单的理解为将泛型 java 代码转 换为普通 java 代码,只不过编译器更直接点,将泛型 java 代码直接转换成普通 java 字节码。 类型擦除的主要过程如下: 一.将所有的泛型参数用其最左边界(最
2021-03-01 13:18:18 106
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人