- 博客(14)
- 收藏
- 关注
原创 我的缺点记录
现在干着六七十岁可以干的事情,要年轻干嘛!10、太别在乎别人的眼光,经常会想到自己之前丢人事,还迟迟不能释怀。9、遇到提升自己的机会,躲躲闪闪,瞻前顾后,怕这怕那,怕失败。6、容易的事情着急做,不容已的事情延迟做,或者躲着不做。7、每年的学习计划,都没有完成,实际上是没有一年完成的。1、知识储备不足,还懒散不学习,三分钟热度。11、不专注听别人讲话,前脚说后脚忘。2、拖延,面对跳战,第一反应是躲。4、不敢大声讲话,应变能力太差。5、唯唯诺诺,不像个男子汉。
2023-06-22 08:41:38
90
原创 合并两个有序数组
public static int[] mergeTwoArray(int[] arr1, int[] arr2) { int i = 0; int j = 0; int k = 0; int len1 = arr1.length; int len2 = arr2.length; int[] res = new int[len1 + len2]; while (i < len1 && i < len2) { ...
2022-02-20 10:26:20
198
原创 入栈顺序是否是出栈顺序
public static boolean isPopOrder01(int[] pushA, int[] popA) { if (pushA.length == 0 || popA.length == 0) { return false; } int popIndex = 0; Stack<Integer> stack = new Stack<>(); for (int num : pushA) { st.
2021-08-19 22:14:03
140
原创 Java String HashCode
public static int hashCode(String value) { int h = 0; int n = value.length(); // 假设 n = 2 if (h == 0 && n > 0) { char val[] = value.toCharArray(); for (int i = 0; i < n; i++) { h = 31 * h + val[i]; .
2021-08-09 19:43:09
149
原创 判断数字是否为回文数字
public static boolean isPalindrome(int x) { if (x < 0 || (x % 10 == 0 && x != 0)) { return false; } int revertedNumber = 0; while (x > revertedNumber) { revertedNumber = revertedNumber * 10 + x % 10; .
2021-08-08 16:44:44
100
原创 找出数组中所有两数之和等于目标数的结果
private static Map<Integer, Integer> resultMap = new HashMap<>(16); public static void twoSum(int[] arr, int target) { ArrayList<ArrayList> result = new ArrayList<>(10); for (int i = 0; i < arr.length; i++) { Arr.
2021-08-08 15:43:21
202
原创 fast-fail 以及 fast-safe
public class TestDemo { // 1、父集合操作会导致子集合出现 fast-fail // 2、子集合增删改查会影响父集合 // 3、删除元素利用迭代器 // 4、多线程需要考虑线程安全 // 5、COW 集合的使用可以避免线程安全问题 private static Object lock = new Object(); // fast-fail fast-safe public static void main(S.
2021-08-06 10:14:50
217
原创 Comparable 和 Comparator
public class Demo01 { // Comparable 自身的能力 private static class SearchResult implements Comparable<SearchResult> { int relativeRatio; long count; int recentOrders; public SearchResult(int relativeRatio, long ...
2021-08-03 21:15:14
80
原创 集合转化为数组
public static void main(String[] args) { List<String> list = new ArrayList<>(10); list.add("a"); list.add("b"); list.add("c"); System.out.println(list); Object[] objects = list.toArray(); // 导致泛型丢失 System.out.pr.
2021-08-03 19:49:06
92
原创 锁粗化
public static void test01() { long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { synchronized (lock){ i++; } } long end = System.currentTimeMillis(); System.out.println("test01-耗时:" + (end - start) + "ms. "); } public
2021-04-18 18:33:02
100
原创 二叉树中最大路径和
import structure.TreeNode; /** 功能描述 二叉树中最大路径和 */ public class Main { private static int res = Integer.MIN_VALUE; public static int getMaxPathSum(TreeNode root) { if (root == null) { return 0; } dfs(root); return res; } public static int dfs(TreeNode ro
2020-12-14 10:29:55
145
原创 最长递增子序列-2020-03
public class Main { public static void getLongestIncrSub(int[] arr) { int len = arr.length; int[] dp = new int[len]; int[] res = new int[len]; Arrays.fill(dp, 1); Arrays.fill(res, 0); int maxNum = 0; for (int i = 0; i < len
2020-12-04 21:33:53
117
1
原创 连续子数组最大和-2020-02
/** * 连续子数组最大和 * @param arr * @return */ public static int getMaxSum(int[] arr) { int curMax = 0; int sumMax = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { curMax = curMax + arr[i]; curMax = Math.max(curMax, 0); sumMax = Math.max(sumMax, cu
2020-12-04 21:32:48
91
原创 两个有序数组的合并-2020-01
两个有序数组的合并 public class Main { public static int[] mergeTwoArray(int[] arr1, int[] arr2) { int i = 0; int j = 0; int k = 0; int len1 = arr1.length; int len2 = arr2.length; int[] res = new int[len1 + len2]; while (i < len1 &a
2020-12-04 21:31:34
105
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅