ffinn92 / Keep-at-solve-it

꾸준히 알고리즘 풀기 위한 스터디 저장소입니다.
2 stars 3 forks source link

[220729][BC][프로그래머스](42746) 가장 큰 수 #109

Closed honeySleepr closed 2 years ago

honeySleepr commented 2 years ago

📌 문제

⭐️ 아이디어

🤔 고민한 내용

💪 새롭게 배운 내용

... Collections.sort(list, Comparator.reverseOrder());

* 위와 같은 클래스를 만들 필요 없이 아래의 코드로 간단하게 정렬 순서를 정의할 수 있다

```java
        Collections.sort(list, (o1, o2) -> {
            String a = String.valueOf(o1) + String.valueOf(o2);
            String b = String.valueOf(o2) + String.valueOf(o1);
            return -(Integer.parseInt(a) - Integer.parseInt(b));
        });

🆘 이해가 어려운 내용

❌ 해결하지 못한 이유

✅ 본인 풀이

원래 생각 했던 풀이(실패) ```java public Number(int n) { this.input = n; if (n < 10) { /* 9 */ this.first = n; this.second = this.first; this.third = this.first; this.forth = this.first; } if (n >= 10 && n < 100) { /* 99 */ this.first = n / 10; this.second = n % 10; this.third = this.first; // this.forth = this.second; } if (n >= 100 && n < 1000) { /* 999 */ this.first = n / 100; this.second = n % 100 / 10; this.third = n % 100 % 10; this.forth = this.first; } if (n >= 1000) { /* 1111 */ this.first = n / 1000; this.second = n % 1000 / 100; this.third = n % 1000 % 100 / 10; this.forth = n % 1000 % 100 % 10; } } @Override public int compareTo(Number o) { if (this.first == o.first) { if (this.second == o.second) { if (this.third == o.third) { return this.input - o.input; } return this.third - o.third; } return this.second - o.second; } return this.first - o.first; } public int getInput() { return input; } } ```

}



## 참고한 자료
- 링크