[반복문]
// 일반적인 반복문 (문자열 접근)
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == 'a') answer++;
}
// 향상된 반복문 (문자열 접근)
for(char c : str.toCharArray()) {
if(c == 'a') answer++;
}
[문자열]
// 문자 하나 대문자 변환
Character.toUpperCase(c);
// 대문자 변환
str.toUpperCase();
// 문자열 문자 하나하나 접근
str.charAt(i);
// char 문자 하나가 숫자인지 문자인지 확인하기
Character.isDigit(x);
// 문자 -> 숫자로 변환
Integer.parseInt(x);
// 숫자 -> 문자열로 변환
String.valueOf(x);
[Stack]
//stack 생성
Stack<Integer> stack = new Stack<>();
//add element
stack.push(x);
//가장 상단에 있는 요소 확인
stack.peek();
//상단에 있는 요소 꺼내기
stack.pop();
//그 외
stack.size();
stack.contains();
[Queue]
// Queue 생성
Queue<Integer> queue = new LinkedList<>();
// add element
queue.offer(x);
// pop element
queue.poll();
// 그 외
queue.isEmpty();
queue.size();
queue.contains();
[Hash Map]
// value 값 가져오기 (없으면 0 반환)
map.getOrDefault(x, 0);
// key가 포함되는지 확인하기
map.containsKey(x);
// key-value 삭제하기
map.remove(x);
// key Set 반환하기
map.keySet();
[조합]
// 조합 구하기
// len 개수 중에서 m개 뽑아내기
static len;
static int[] combi;
public void DFS(int L, int s) {
if(L==m) {
// combi[i] 에 조합 인덱스 번호가 저장되어있음
} else {
for(int i=s; i<len; i++) {
combi[L]=i;
DFS(L+1, i+1);
}
}
}
'개인 공부 > 코딩테스트' 카테고리의 다른 글
[LeetCode] 169번 (Majority Element) (0) | 2023.08.25 |
---|---|
[LeetCode] 80번 (Remove Duplicates Sorted Array 2) (0) | 2023.08.25 |
[LeetCode] 26번 (Remove Duplicates Sorted Array 1) (0) | 2023.08.24 |
[LeetCode] 27번 (Remove Element) (0) | 2023.08.24 |
[LeetCode] 88번(Merge Sorted Array) (0) | 2023.08.22 |