-
1356. Sort Integers by The Number of 1 Bits javaLeetCode_Study_Plan/Programming Skills 2022. 9. 24. 16:10
class Solution { public int[] sortByBits(int[] arr) { Integer[] a = new Integer[arr.length]; for (int i = 0; i < a.length; i++) { a[i] = arr[i]; } // Arrays.sort(a, (i, j) -> Integer.bitCount(i) != Integer.bitCount(j) ? Integer.bitCount(i) - Integer.bitCount(j) : i - j); Arrays.sort(a, Comparator.comparing(i -> Integer.bitCount(i) * 10000 + i)); for (int i = 0; i < a.length; i++) { arr[i] = a[i]; } return arr; } }
https://st-lab.tistory.com/243
# TODO
람다식
https://tourspace.tistory.com/9
https://stackoverflow.com/questions/21970719/java-arrays-sort-with-lambda-expression
'LeetCode_Study_Plan > Programming Skills' 카테고리의 다른 글
303. Range Sum Query - Immutable java (0) 2022.09.25 1603. Design Parking System java (0) 2022.09.25 217. Contains Duplicate java (0) 2022.09.24 242. Valid Anagram java (0) 2022.09.24 232. Implement Queue using Stacks java (0) 2022.09.24