ArrayList
- add(int idx)
- remonve(int idx)
- size()
Pair로 Queue 구현
class Pair {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public void compareTo(Pair pair) {
return Integer.compare(this.x, pair.x);
}
}
Queue<Pair> queue = new LinkedList<>();
queue.add(new Pair(x, y));
Pair t = queue.poll();
PriorityQueue<Pair>pq = new PriorityQueue<>();
pq.add(new Pair(start, 0));
while(!pq.isEmpty()){
Pair now = pq.poll();
}
int[] arr = new int[n];
Arrays.sort(arr);
Arrays.sort(arr, Collections.reverseOrder());
String to Int
- Integer.parseInt(“123”)
Int to String
- Integer.toString(123)
- String.valueOf(123)
Integer.compare(1, 2); // 왼쪽 작으면 -1
Integer.compare(2, 2); // 같으면 0
Integer.compare(2, 1); // 왼쪽 크면 1
String.charAt('a') != 'b' // char는 '==' , '!=' 비교로 가능
str.substring(int beginIndex, int endIndex) -> begin ~ end-1까지의 값을 리턴
str = str.replaceAll("0", "1") //str에 0을 다 1로 바꾸기
int[] -> length
String -> length()
// String 정렬
String str = "basde";
char[] arr = str.toCharArray(); //String -> char[]
Arrays.sort(arr); //String, char[] 둘다 정렬 가능
String result = new String(arr); //char[] -> String
System.out.println(result);
'⚖️Algorithm' 카테고리의 다른 글
[코딩테스트] 자주 사용하는 함수(조합/순열/중복조합/중복순열) c++ (0) | 2022.11.03 |
---|---|
[코딩테스트] 알고리즘 정리 (0) | 2022.10.22 |
[SQL] 코딩테스트 준비 (0) | 2022.10.20 |
[Algorithm] 프로그래머스 - 여행경로 (C++) (0) | 2022.10.15 |
[java] 지식 (0) | 2022.09.23 |