์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ ํจ์ค ์ค์ผ์ค๋ฌ
- docker-compose kafka
- ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ
- docker compose
- private subnet ec2 ๋ก์ปฌ ์ ์
- ์๋ฐ
- Entity
- ๋ค์ค ์ปจํ ์ด๋
- Codedeploy ์ค๋ฅ
- s3 ์ด๋ฏธ์ง ๋ค์ด๋ก๋
- JPA
- s3 ์ด๋ฏธ์ง ์ ์ฅ
- redis ํ ์คํธ์ฝ๋
- prod docker-compose
- AWS Certified Solutions Architect - Associate
- docker
- s3 log ์ ์ฅ
- nGrinder
- ์ ํจ์ค ๋น๋ ์ค๋ฅ
- docker ps -a
- Kafka
- ํ์ดํผ๋ฐ์ด์
- ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ
- aws ์ฟ ํฐ
- redis ์กฐํ
- aws saa ํฉ๊ฒฉ
- ์คํํ๋ ๋ฏธ์ค
- @RestControllerAdvice
- ์๋ฒ ํฐ์ง๋ ๋์ปค ์ฌ์คํ
- Today
- Total
๐๐ข๐๐ โ๐๐๐ ๐๐๐ก๐๐ ๐๐๐๐โง
[Java] ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ & ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ ๋ณธ๋ฌธ
[Java] ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ & ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ
๐คRyusun๐ค 2024. 4. 11. 15:45๋งค์ผ ์ฝํ ๋ฌธ์ ๋ฅผ ํ๊ณ ์์ง๋ง ๋ธ๋ก๊ทธ์๋ ์ค๋๋ง์ ์ฝํ ๋ฌธ์ ๋ฅผ ์ฌ๋ ค๋ณธ๋ค.
1. ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ(Lv.2)
๋จ์ BFS ๋ฌธ์ ์ด๋ค. ์ผ๋ฐ BFS๋ฐฉ์์ผ๋ก ํ๋ฉด ์ฝ๊ฒ ํ๋ฆฌ๋ ๋ฌธ์ ์ด๋ค.
๋ค๋ฅธ ์์ด๋ฉด cnt++ ํ๊ณ bfs๋ก ํด๋น ์์ ๊ฐ์๋ฅผ ์ธ์ max_cnt๋ฅผ ๊ฐฑ์ ํด์ฃผ๋ ๋ฐฉ์์ผ๋ก ํ์๋ค.
import java.util.*;
class Solution {
static boolean[][] visited;
static int[] dx = {1, 0, -1, 0};
static int[] dy = {0, -1, 0, 1};
static int max_cnt;
public int[] solution(int m, int n, int[][] picture) {
visited = new boolean[m][n];
int cnt = 0;
max_cnt = 0;
for (int i =0 ; i < m; i++){
for (int j = 0; j < n; j++){
if (picture[i][j] != 0){
bfs(i, j, m, n, picture);
cnt++;
}
}
}
int[] answer = {cnt, max_cnt};
return answer;
}
private static void bfs(int a, int b, int m, int n, int[][] picture){
Queue<int[]> queue = new LinkedList<>();
queue.offer(new int[] {a,b});
visited[a][b] = true;
int num = picture[a][b];
int num_cnt = 1;
picture[a][b] = 0;
while (!queue.isEmpty()){
int[] now = queue.poll();
int x = now[0];
int y = now[1];
for (int i = 0; i< 4; i++){
int nx = dx[i] + x;
int ny = dy[i] + y;
if (nx < 0 || ny < 0 || nx > m-1 || ny > n-1) continue;
if (visited[nx][ny]) continue;
if (picture[nx][ny] == 0 || picture[nx][ny] != num) continue;
visited[nx][ny] = true;
picture[nx][ny] = 0; //๋ฐฉ๋ฌธํ์ผ๋ฉด picture์์ ํด๋น ์นธ์ 0์ผ๋ก ๋ง๋ค๊ธฐ
queue.offer(new int[] {nx,ny});
num_cnt++;
}
}
max_cnt = Math.max(max_cnt, num_cnt); // ๋ค ๋์์ผ๋ฉด max_cnt๊ฐ ๊ฐฑ์
}
}
2. ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ(Lv.3)
๋ค์ต์คํธ๋ผ ๋ฌธ์ ์ด๋ค.
ํด๋น ๋ฌธ์ ๋ ๋ฐฑ์ค 1504 ํน์ ํ ์ต๋จ๊ฒฝ๋ก์ ๋ฌธ์ ์ ๋น์ทํ๋ค.
ํ์๋ 1504๋ฌธ์ ํ์ด์ ๋น์ทํ๊ฒ ํ์๋๋ ํ์ ์์๋ค.
๋ ธ๋๋ ์๋ฐฉํฅ์ด๊ธฐ๋๋ฌธ์ ์ต๋จ ๊ฑฐ๋ฆฌ๋ a -> i = i ->a ๊ฐ ๋๊ฐ๋ค.
๋ฐ๋ผ์ s์์ ์ถ๋ฐํ ์ต๋จ ๊ฒฝ๋ก , a์์ ์ถ๋ฐํ ์ต๋จ ๊ฒฝ๋ก, b์์ ์ถ๋ฐํ ์ต๋จ ๊ฒฝ๋ก๋ฅผ ๊ตฌํด์ฃผ๊ณ ์,
(s์์ ์ถ๋ฐํ์ฌ ๊ฐ i๋ฒ ๋ ธ๋๊น์ง ์ต๋จ ๊ฑฐ๋ฆฌ) + (i๋ฒ ๋ ธ๋์์ a๊น์ง์ ์ต๋จ ๊ฑฐ๋ฆฌ) + (i๋ฒ ๋ ธ๋์์ b๊น์ง์ ์ต๋จ ๊ฑฐ๋ฆฌ) ์ ์ต์ํฉ์ ๊ตฌํด์คฌ๋ค.
import java.util.*;
class Solution {
static ArrayList<Node>[] graph;
public int solution(int n, int s, int a, int b, int[][] fares) {
graph = new ArrayList[n+1];
for (int i = 1; i <= n; i++) {
graph[i] = new ArrayList<>();
}
for (int[] fare : fares) {
int start = fare[0];
int end = fare[1];
int cost = fare[2];
graph[start].add(new Node(end, cost));
graph[end].add(new Node(start, cost));
}
int[] S = dijkstra(s, n); // s์์ ์ถ๋ฐ
int[] A = dijkstra(a, n); // a์์ ์ถ๋ฐ
int[] B = dijkstra(b, n); // b์์ ์ถ๋ฐ
int min = Integer.MAX_VALUE;
for(int i=1; i<=n; i++) {
// (s์์ i๋
ธ๋๊น์ง ๊ฑฐ๋ฆฌ) + (i๋
ธ๋์์ a๊น์ง์ ๊ฑฐ๋ฆฌ) + (i๋
ธ๋์์ b๊น์ง์ ๊ฑฐ๋ฆฌ) ์ ์ต์๋ฅผ ๊ตฌํด์ค๋ค.
if(min > S[i] + A[i] + B[i]) {
min = S[i] + A[i] + B[i];
}
}
return min;
}
public static int[] dijkstra(int start, int n) {
PriorityQueue<Node> pq = new PriorityQueue<>();
boolean[] visited = new boolean[n+1];
int[] dist = new int[n+1];
Arrays.fill(dist, Integer.MAX_VALUE); // ์ต๋๊ฐ์ผ๋ก ์ด๊ธฐํ
dist[start] = 0;
pq.add(new Node(start, 0));
while (!pq.isEmpty()) {
Node now = pq.poll();
int idx = now.index;
if (visited[idx]) continue;
visited[idx] = true;
for (Node next : graph[idx]) {
int cost = dist[idx] + next.cost;
if (dist[next.index] > cost) {
dist[next.index] = cost;
pq.offer(new Node(next.index, cost));
}
}
}
return dist;
}
public static class Node implements Comparable<Node> {
int index;
int cost;
public Node(int index, int cost){
this.index = index;
this.cost = cost;
}
@Override
public int compareTo(Node o){
return Integer.compare(this.cost, o.cost);
}
}
}
๊ถ๊ธํ์ ์ด ์๋ค๋ฉด ๋๊ธ ๋ฌ์์ฃผ์ธ์ฉ^_^
'๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด๐ป > ๐๐๐ฏ๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Review] JVM ๋ฐ๋ฐ๋ฅ๊น์ง ํํค์น๊ธฐ - 1. ์๋ฐ ๊ธฐ์ ์์คํ (0) | 2025.02.01 |
---|---|
[Java] Action Tag (0) | 2022.10.28 |
[Java] JSP, Directive (0) | 2022.10.27 |
[Java] PriorityQueue (0) | 2022.10.19 |
[Java] Generic Method ์ ๋ค๋ฆญ ๋ฉ์๋ (0) | 2022.10.12 |