随笔分类 -  algorithm

进军算法
摘要:public static void main(String[] args) { int[] a = {1, 4, 6, 2, 15, 24, 67, 45, 23, 99, 12, 8}; selectSort(a); System.out.println(Arrays.toString(a)); 阅读全文
posted @ 2024-11-28 15:00 人在京城 阅读(13) 评论(0) 推荐(0)
摘要:1、树结构类 public class TreeNode<T> { T val; TreeNode<T> parent; TreeNode<T> right; TreeNode<T> left; public TreeNode(){ } public TreeNode(T val){ this.va 阅读全文
posted @ 2024-01-28 16:41 人在京城 阅读(60) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2024-01-25 08:47 人在京城 阅读(1) 评论(0) 推荐(0)
摘要:public class Tree { public static void main(String[] args) { Tree root = new Tree(50); Tree.insert(root, 30); Tree.insert(root, 60); Tree.insert(root, 阅读全文
posted @ 2024-01-24 17:50 人在京城 阅读(14) 评论(0) 推荐(0)
摘要:1、直接上代码 public static boolean isPalindrome(String s) { //1、判断字符串是否是null或者是空字符,如果是就返回true if (s == null && "".equals(s.trim())) { return true; } //2、移除 阅读全文
posted @ 2022-11-26 22:46 人在京城 阅读(41) 评论(0) 推荐(0)
摘要:1、左右碰撞指针,类似于二分法查找 1 /** 2 * 查找是否存在目标值 时间复杂度 O(logN) 3 * 有序的数组,查可以这样用 4 * @param array 5 * @param target 6 * @return 7 */ 8 public static boolean findT 阅读全文
posted @ 2021-12-28 14:02 人在京城 阅读(49) 评论(0) 推荐(0)
摘要:1、栈,LIFO-后进先出数据结构。 /** * 给定一个只包括 '(',')','{','}','[',']'的字符串 s ,判断字符串是否有效。 * 有效字符串需满足: * 左括号必须用相同类型的右括号闭合。 * 左括号必须以正确的顺序闭合。 * * 示例 1: * 输入:s = "()" * 阅读全文
posted @ 2021-12-28 13:52 人在京城 阅读(24) 评论(0) 推荐(0)
摘要:public static boolean isLooped(int num) { StringBuilder strBuilder = new StringBuilder(String.valueOf(num)); int l = 0; //左指针 int r = strBuilder.lengt 阅读全文
posted @ 2021-07-09 13:38 人在京城 阅读(50) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { Tree treeG = new Tree('G', null, null); Tree treeD = new Tree('D', null, null); Tree treeF = new Tree('F', nu 阅读全文
posted @ 2021-07-01 11:25 人在京城 阅读(194) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { System.out.println(JSON.toJSON(kingRing(41, 3))); } //链表实现-删除效率高-不需要复制或移动元素 public static Integer[] kingRing( 阅读全文
posted @ 2021-06-29 11:41 人在京城 阅读(40) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { int[] value = {100, 150, 350}; int[] weight = {1, 4, 3}; System.out.println(dynamic(5, value, weight)); } /** 阅读全文
posted @ 2021-06-28 16:48 人在京城 阅读(35) 评论(0) 推荐(0)
摘要:import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * @author: small-sunshine * @Descrip 阅读全文
posted @ 2021-06-25 14:57 人在京城 阅读(325) 评论(0) 推荐(0)
摘要:import java.io.*; import java.text.DecimalFormat; /** * @author: small sunshine * @Description: * @date: 2021/6/20 10:04 上午 */ public class ScoreDescS 阅读全文
posted @ 2021-06-24 12:42 人在京城 阅读(88) 评论(0) 推荐(0)
摘要:/** * 冒泡排序-稳定的,两个相同的数-相对位置不变 * * @param num * @return */ public static int[] bubbleSort(int[] num) { if (Objects.isNull(num) || num.length <= 1) { ret 阅读全文
posted @ 2021-06-23 14:00 人在京城 阅读(31) 评论(0) 推荐(0)
摘要:import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; /** * @author: Small sun shine * @Description: * @date: 2021/6/20 9:40 上午 */ @Slf4 阅读全文
posted @ 2021-06-20 10:17 人在京城 阅读(33) 评论(0) 推荐(0)
摘要://递归,累计+1,非尾递归 public static int cap(int n) { if (n == 1) { return 1; } return cap((n - 1)) + 1; } //递归,累计+1,尾递归 public static int capTail(int n, int 阅读全文
posted @ 2021-06-19 18:35 人在京城 阅读(89) 评论(0) 推荐(0)
摘要:/** * 双指针-数组反转 * * @param array * @return */ public static int[] coverArray(int[] array) { if (array == null && array.length == 0) { return array; } i 阅读全文
posted @ 2021-06-17 16:01 人在京城 阅读(49) 评论(0) 推荐(0)
摘要:public class StrCutDown { /** * 字符串压缩范围[a-zA-Z] 输入如:aaabbbccca =>> a3b3c3a1 * 压缩后的字符串要小于原字符串,否则返回原字符串 * @param args */ public static void main(String[ 阅读全文
posted @ 2021-06-16 13:41 人在京城 阅读(279) 评论(0) 推荐(0)
摘要:@Slf4j public class AgeTotal { public static String file = "/Desktop/age.txt"; public static int total = 10000 * 10000; public static int maxAge = 180 阅读全文
posted @ 2021-06-15 16:54 人在京城 阅读(91) 评论(0) 推荐(0)
摘要:public class DoublePointer { public static int[] a = new int[]{1, 3, 4, 9}; public static int[] b = new int[]{0, 3, 4, 4}; public static void main(Str 阅读全文
posted @ 2021-06-15 16:09 人在京城 阅读(346) 评论(0) 推荐(0)