-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 크기가 작은 부분 문자열 * 미로 탈출 명령어 * 압축 * 거스름돈 * 우박 수열 정적분
- Loading branch information
1 parent
27dc670
commit 227877d
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
public int solution(int n, int[] money) { | ||
int[] count = new int[n+1]; | ||
count[0] = 1; | ||
for (int m: money) { | ||
for (int value=0;value<n;value++) { | ||
if (value+m > n) break; | ||
count[value+m] += count[value]; | ||
} | ||
} | ||
|
||
return count[n] % 1_000_000_007; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
|
||
int n, m, r, c, k; | ||
String answer = "impossible"; | ||
ArrayDeque<String> path = new ArrayDeque<>(); | ||
int count = 0;; | ||
|
||
Direction[] directions = { | ||
new Direction("d", 1, 0), | ||
new Direction("l", 0, -1), | ||
new Direction("r", 0, 1), | ||
new Direction("u", -1, 0) | ||
}; | ||
|
||
public String solution(int n, int m, int x, int y, int r, int c, int k) { | ||
x--; | ||
y--; | ||
r--; | ||
c--; | ||
this.n = n; | ||
this.m = m; | ||
this.r = r; | ||
this.c = c; | ||
this.k = k; | ||
|
||
dfs(new Node(x, y)); | ||
|
||
return answer; | ||
} | ||
|
||
void dfs(Node now) { | ||
|
||
if (!answer.equals("impossible")) { | ||
return; | ||
} | ||
|
||
if (Math.abs(now.x-r) + Math.abs(now.y-c) > k-count) { | ||
return; | ||
} | ||
|
||
if ((Math.abs(now.x-r) + Math.abs(now.y-c) + k-count) % 2 != 0) { | ||
return; | ||
} | ||
|
||
if (count == k) { | ||
if (now.x == r && now.y == c) { | ||
answer = String.join("", path); | ||
} | ||
return; | ||
} | ||
|
||
for (Direction direction: directions) { | ||
int nextX = now.x + direction.dx; | ||
int nextY = now.y + direction.dy; | ||
|
||
if (nextX < 0 || nextX >= n || nextY < 0 || nextY >= m) { | ||
continue; | ||
} | ||
|
||
count++; | ||
path.addLast(direction.name); | ||
dfs(new Node(nextX, nextY)); | ||
count--; | ||
path.removeLast(); | ||
} | ||
} | ||
|
||
class Node { | ||
int x; | ||
int y; | ||
Node(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
} | ||
|
||
class Direction { | ||
String name; | ||
int dx; | ||
int dy; | ||
Direction(String name, int dx, int dy) { | ||
this.name = name; | ||
this.dx = dx; | ||
this.dy = dy; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
public int[] solution(String msg) { | ||
HashMap<String, Integer> map = new HashMap<>(); | ||
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
int idx = 1; | ||
for (int i=0;i<26;i++) { | ||
map.put(alpha.substring(i, i+1), idx++); | ||
} | ||
|
||
ArrayList<Integer> answer = new ArrayList<>(); | ||
int i = 0; | ||
int N = msg.length(); | ||
while (i < N) { | ||
String word = msg.substring(i, i+1); | ||
i++; | ||
|
||
// 사전에 없는 단어가 나올 때까지 | ||
while (i < N && map.containsKey(word)) { | ||
word += msg.substring(i, i+1); | ||
i++; | ||
} | ||
|
||
// 사전에 존재하지 않는다면 | ||
if (!map.containsKey(word)) { | ||
answer.add(map.get(word.substring(0, word.length()-1))); | ||
map.put(word, idx++); | ||
i--; | ||
} else { | ||
answer.add(map.get(word)); | ||
} | ||
} | ||
return answer.stream().mapToInt(x -> x).toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
public double[] solution(int k, int[][] ranges) { | ||
ArrayList<Integer> y = new ArrayList<>(); | ||
y.add(k); | ||
while (k != 1) { | ||
if (k % 2 == 0) { | ||
k /= 2; | ||
} else { | ||
k = k * 3 + 1; | ||
} | ||
y.add(k); | ||
} | ||
|
||
double[] sums = new double[y.size()]; | ||
for (int i=0;i<y.size()-1;i++) { | ||
sums[i+1] = (y.get(i)+y.get(i+1)) / (double)2; | ||
} | ||
for (int i=1;i<sums.length;i++) { | ||
sums[i] += sums[i-1]; | ||
} | ||
System.out.println(Arrays.toString(sums)); | ||
double[] answer = new double[ranges.length]; | ||
for (int i=0;i<ranges.length;i++) { | ||
int[] range = ranges[i]; | ||
int x1 = range[0]; | ||
int x2 = sums.length+range[1]-1; | ||
|
||
if (x1 > x2) { | ||
answer[i] = -1; | ||
} else if (x1 == x2) { | ||
answer[i] = 0; | ||
} else { | ||
answer[i] = sums[x2] - sums[x1]; | ||
} | ||
} | ||
|
||
return answer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Solution { | ||
public int solution(String t, String p) { | ||
int N = t.length(); | ||
int M = p.length(); | ||
|
||
long pLong = Long.parseLong(p); | ||
int answer = 0; | ||
for (int i=0;i<=N-M;i++) { | ||
if (Long.parseLong(t.substring(i, i+M)) <= pLong) { | ||
answer++; | ||
} | ||
} | ||
return answer; | ||
} | ||
} |