Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions coin-change/sora0319.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Arrays;

class Solution {
public int coinChange(int[] coins, int amount) {
int[] dp = new int[amount + 1];
Arrays.fill(dp, amount + 1); // 최대값으로 초기화 (amount + 1은 절대 나올 수 없는 큰 값)
dp[0] = 0; // 0원을 만들 때는 동전 0개

for (int i = 1; i <= amount; i++) {
for (int coin : coins) {
if (i - coin >= 0) {
dp[i] = Math.min(dp[i], dp[i - coin] + 1);
}
}
}

return dp[amount] > amount ? -1 : dp[amount];
}
}


21 changes: 21 additions & 0 deletions find-minimum-in-rotated-sorted-array/sora0319.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public int findMin(int[] nums) {
int start = 0;
int end = nums.length-1;


while(start < end){
int mid = (start + end) / 2;

if(nums[mid] < nums[end]){
end = mid;
}
else{
start = mid + 1;
}
}

return nums[start];
}
}

10 changes: 10 additions & 0 deletions maximum-depth-of-binary-tree/sora0319.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public int maxDepth(TreeNode root) {
if(root == null){
return 0;
}

return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}

40 changes: 40 additions & 0 deletions merge-two-sorted-lists/sora0319.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode answer = new ListNode(0, null);
ListNode merged = answer;

while(list1 != null || list2 != null){
if(list1 == null){
merged.next = list2;
break;
}
if(list2 == null){
merged.next = list1;
break;
}
if(list1.val <= list2.val){
merged.next = list1;
list1 = list1.next;
}
else{
merged.next = list2;
list2 = list2.next;
}

merged = merged.next;
}

return answer.next;
}
}

42 changes: 42 additions & 0 deletions word-search/sora0319.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Solution {
public boolean exist(char[][] board, String word) {
boolean[][] visited = new boolean[board.length][board[0].length];
boolean status = false;

for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
if(word.charAt(0) == board[i][j]){
visited[i][j] = true;
status = checkingWord(board, word, visited, 1, i, j);
visited[i][j] = false;
}
if(status) return true;
}
}

return false;
}
public boolean checkingWord(char[][] board, String word, boolean[][] visited, int same, int x, int y){
if(same == word.length()) return true;
int[] mx = {-1,1,0,0};
int[] my = {0,0,-1,1};

for(int k = 0; k < 4; k++){
int nx = mx[k] + x;
int ny = my[k] + y;

if(nx < 0 || ny < 0 || nx >= board.length || ny >= board[0].length) continue;
if(visited[nx][ny]) continue;

boolean status = false;

if(word.charAt(same) == board[nx][ny]){
visited[nx][ny] = true;
if(checkingWord(board, word, visited, same + 1, nx, ny)) return true;
visited[nx][ny] = false;
}
}
return false;
}
}