diff --git a/CoinChange.java b/CoinChange.java new file mode 100644 index 0000000..8e883db --- /dev/null +++ b/CoinChange.java @@ -0,0 +1,23 @@ +class Solution { + public int coinChange(int[] coins, int amount) { + if (amount == 0) return 0; + int[] change = new int[amount+1]; + change[0] = 0; + for (int c : coins) { + if (c <= amount) + change[c] = 1; + } + for (int i = 1; i <= amount; i++) { + if (change[i] == 1) continue; + int min = -1; + for (int c:coins) { + if (i - c>0 && change[i-c] != -1) { + int withC = change[i-c] + 1; + min = min < 0 ? withC : Math.min(withC, min); + } + } + change[i] = min; + } + return change[amount]; + } +} diff --git a/Strong Password Checker b/Strong Password Checker new file mode 100644 index 0000000..e9ed0cb --- /dev/null +++ b/Strong Password Checker @@ -0,0 +1,16 @@ +import java.util.regex.*; +class Solution { + public int strongPasswordChecker(String password) { + Pattern strongPattern = Pattern.compile("^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9!\\.]{6,20}$"); + if (strongPattern.matcher(password).matches()) return 0; + + if (password.length() <= 3) {return 6-password.length();} + int distance = 0; + if (password.length() > 20) {distance = password.length()-20; } + + + Pattern repeatedChar = Pattern.compile("([A-Za-z0-9])\1\1"); + if (repeatedChar.matcher(password).matches()) distance++; + return distance; + } +}