文章

REMOVE JAVA SDK

  sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\ Support/Oracle/Java cd /Library/Java/JavaVirtualMachines rm -fr /usr/local/opt/openjdk@11/libexec/openjdk.jdk sudo rm -rf ****.jdk

JAVA - JPA

HIBERNATE hibernate.ddl-auto : create : will delete and create new table every startup , so will make data lost create-drop : same as create but will delete and create when session down and up update : create when first time and update every startup keep date validate : check and create/update tables every startp none : do noting JPA GeneratedValue(strategy = GenerationType.XXXXXX) the strategy of primary key TABLE: need to use with @TableGenerator  SEQUENCE: use Sequnce (like a temp table) ony Orcale , PSQL,DB2 support IDENTITY:  control by table(database) ORacle not support AUTO : Default ,control by springboot 在Hibernate中,提供了懒加载功能,当需要的时候才查询具体数据,但是在使用@OneToOne关系时, FetchType.LAZY看起来不会生效。 当你查询一个实体类A,这个实体类A持有另一个实体类B的引用,但是A中并没有记录B的主键,这种情况下,即使有懒加载注解,查询实体A的时候依然会执行两条SQL,分别查询实体类A和B对应的表A和表B。这是由于Hibernate的机制导致,并不是你的使用方式有问题或者存在其他bug。 ———————————————— 版权声明:本文为CSDN博主「_古井心」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u010234516/article/details/103011494

JAVA - DSF Example

  class Solution { class Point { int x ; int y ; int steps ; public Point ( int x , int y , int steps ){ this . x = x; this . y = y; this . steps = steps; } } public int shortestPathBinaryMatrix ( int [][] grid ) { //BFS //DFS //BFS -> Shortest path //DSA : Queue if (grid[ 0 ][ 0 ] != 0 ){ return - 1 ; } int [][] moves = new int [][]{{ 0 ,- 1 } , { 0 , 1 } , { 1 , 0 }, {- 1 , 0 } , {- 1 ,- 1 },{- 1 , 1 },{ 1 , 1 },{ 1 ,- 1 }}; Stack < Point > queue = new Stack <>(); queue . push ( new Point ( 0 , 0 , 1 )); grid[ 0 ][ 0 ] = 1 ; int newX = 0 ; int newY = 0 ; while (! queue . isEmpty ()){ Point point = queue . pop (); if ( point . x == grid . length - 1 && point . y == grid[ 0 ]. length - 1 ){ ...

JAVA - BSF Example

 Leetcode 1091 class Solution { class Point{ int x ; int y ; int steps; public Point(int x, int y , int steps){ this.x = x; this.y = y; this.steps = steps; } } public int shortestPathBinaryMatrix(int[][] grid) { //BFS //DFS //BFS -> Shortest path //DSA : Queue if(grid[0][0] != 0){ return -1; } int [][] moves = new int[][]{{0,-1} , {0,1} , {1,0}, {-1,0} , {-1,-1},{-1, 1},{1,1},{1,-1}}; Queue<Point> queue = new LinkedList<>(); queue.offer(new Point(0 , 0, 1)); grid[0][0] = 1; int newX = 0; int newY = 0; while(! queue.isEmpty()){ Point point = queue.poll(); if(point.x == grid.length -1 && point.y == grid[0].length-1){ return point.steps; } for(int i = 0 ;i<8 ; i++){ newX = point.x...

MAP - Sort with stream

 LEETCODE 1636 Given an array of integers   nums , sort the array in   increasing   order based on the frequency of the values. If multiple values have the same frequency, sort them in   decreasing   order. Return the  sorted array . Example 1: Input: nums = [1,1,2,2,2,3] Output: [3,1,1,2,2,2] Explanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3. Example 2: Input: nums = [2,3,1,3,2] Output: [1,3,3,2,2] Explanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order. Example 3: Input: nums = [-1,1,-6,4,5,-6,1,4,1] Output: [5,-1,4,4,-6,-6,1,1,1] #1 class Solution { public int[] frequencySort(int[] nums) { return Arrays.stream(nums) .boxed() // boxing to wapped class .collect(Collectors.toMap(e-> e , e-> 1 , Integer::sum))//?? .entrySet() .stream() .sorted((e1,e2) -> e1.getValue().equals(e...

Java - Math Find All Numbers

class Solution { public int addDigits ( int num ) { if (num < 10 ){ return num; } int ans = 0 ; while (num!= 0 ){ ans += num % 10 ; num /= 10 ; } if (ans >= 10 ){ return addDigits (ans); } return ans; } }

MATH - 5c2 , 6c3... combinations

  public int combinationOf(int n, int r) { return factorial(n) / factorial(r) / factorial(n - r); // int -> overflow, long } // ni. 4! = 4 x 3 x 2 x 1 public int factorial(int n ) { if (n <= 1) return 1; return n * factorial(n - 1); }