Algorithm/java tip
-
Tip4Algorithm/java tip 2020. 4. 19. 18:24
문제 : https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/ 참고 : https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/discuss/118471/Java-2-lines // L, R 사이의 숫자중 2진수 표현에 1의 개숫가 소수인 수의 갯수 리턴 public int countPrimeSetBits(int L, int R) { int ans = 0; for(int i=L; i
-
Tip3(Easy)Algorithm/java tip 2020. 4. 14. 11:49
문제 : https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/submissions/ 참고 : https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/discuss/455682/Java-100-time-and-memory-Bit-Operations-(concise) List bsArray = new ArrayList(); public int sumRootToLeaf(TreeNode root) { StringBuilder sb = new StringBuilder(); sum(root, sb); int ans = 0; for(String s : bsArray) { ans += Integ..
-
Tip2(easy)Algorithm/java tip 2020. 4. 13. 15:12
문제 : https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/ public int[] sortByBits(int[] arr) { // 2진수로 1의 갯수로 오름차순 정렬 // 똑같으면 그냥 오름차순 Data[] data = new Data[arr.length]; for(int i=0; i e.n).mapToInt(e -> e).toArray(); } class Data implements Comparable { public Data(int n, String bn, int cnt) { this.n = n; this.bn = bn; this.cnt = cnt; } int n; String bn; int cnt; @Override publi..