Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 코딩테스트
- Counting
- SQL
- Number Theory
- Stack
- greedy
- Tree
- Matrix
- 코테
- Data Structure
- Binary Search
- hash table
- geometry
- database
- sorting
- 파이썬
- implement
- two pointers
- dynamic programming
- Method
- Class
- java
- 자바
- string
- Binary Tree
- Math
- simulation
- array
- 구현
- bit manipulation
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.1] 문자열 내 마음대로 정렬하기 본문
1. Input, Output, Example

- 각 문자열의 인덱스 n번째 글자를 기준으로 오름차순 정렬된 결과를 반환
2. Constraint
1) strings는 길이 1 이상, 50이하인 배열이다.
2) strings의 원소는 소문자 알파벳으로 이루어져 있다.
3) strings의 원소는 길이 1 이상, 100이하인 문자열이다.
4) 모든 strings의 원소의 길이는 n보다 크다.
5) 인덱스 1의 문자가 같은 문자열이 여럿 일 경우, 사전순으로 앞선 문자열이 앞쪽에 위치한다.
3. Code
import java.util.*;
class Solution {
public String[] solution(String[] strings, int n) {
Arrays.sort(strings, new Comparator<>(){
@Override
public int compare(String s1, String s2){
int ans = s1.charAt(n)-s2.charAt(n);
if(ans==0) return s1.compareTo(s2);
return ans;
}
});
return strings;
}
}
- +1
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.1] 명예의 전당 (1) (0) | 2023.06.30 |
---|---|
[프로그래머스/Lv.1] 콜라 문제 (0) | 2023.06.30 |
[프로그래머스/Lv.0] 특이한 정렬 (0) | 2023.06.30 |
[LeetCode/Easy] 2696. Minimum String Length After Removing Substrings (0) | 2023.06.30 |
[LeetCode/Easy] 2682. Find the Losers of the Circular Game (0) | 2023.06.29 |