-
1356. Sort Integers by The Number of 1 Bits javaLeetCode_Study_Plan/Programming Skills 2022. 9. 24. 16:10
Sort Integers by The Number of 1 Bits - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
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
자바 [JAVA] - Comparable 과 Comparator의 이해
아마 이 글을 찾아 오신 분들 대개는 Comparable과 Comparator의 차이가 무엇인지 모르거나 궁금해서 찾아오셨을 것이다. 사실 알고보면 두 개는 그렇게 어렵지 않으나 아무래도 자바를 학습하면서 객
st-lab.tistory.com
# TODO
람다식
https://tourspace.tistory.com/9
Java 8 Comparator
이번에는 Comparator interface에 대해서 다룹니다. 정렬을 하기 위해서 구현하는 클래스 이면 Collection.sort()를 통하여 list를 소팅하거나, TreeMap같이 정렬이 필요한 자료구조에 Comparable과 같이 구현하
tourspace.tistory.com
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