Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved 풍선 터트리기 - 135MB 23.16ms #234

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions Programmers/불량사용자/불량사용자_김현준.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.*;

class Solution {
static List<Set<String>> firstSet = new ArrayList<>();
static Set<Set<String>> finalSet = new HashSet<>();
static int ans = 0;
static boolean[] v;
public int solution(String[] user_id, String[] banned_id) {
int answer = 1;
// 가능한 모든 경우를 탐색
for(int i=0;i<banned_id.length;i++) {
char[] c = banned_id[i].toCharArray();
Set<String> set = new HashSet<>();
for(int j=0;j<user_id.length;j++) {
int cnt = 0;
for(int k=0;k<user_id[j].length();k++) {
// k 가 banned_id 보다 갯수가 많으면 x
if(k > c.length - 1) break;
if(c[k] == '*' || c[k] == user_id[j].charAt(k)) {
cnt++;
}

if(cnt == c.length && k == user_id[j].length()-1) {
set.add(user_id[j]);
}
}
}
firstSet.add(set);
}

System.out.println(firstSet.toString());
// 여기서 dfs로 순서 상관없이 조회가능한 갯수 체크
// v = new boolean[set.size()];
dfs(0, new HashSet<>(), banned_id.length);
// System.out.println(finalSet.toString());
return finalSet.size();
}

public static void dfs(int idx, Set<String> current, int size) {
// basis
if(idx == size) {
finalSet.add(new HashSet<>(current));
return;
}

for(String user : firstSet.get(idx)) {
if(!current.contains(user)) {
current.add(user);
dfs(idx + 1, current, size);
current.remove(user);
}
}
}
}
22 changes: 22 additions & 0 deletions Programmers/풍선터트리기/풍선터트리기_김현준.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public int solution(int[] a) {
int[] left = new int[a.length];
int[] right = new int[a.length];
left[0] = a[0];
right[a.length-1] = a[a.length-1];
for(int i=1;i<a.length;i++) {
left[i] = Math.min(left[i-1], a[i]);
}

for(int i=a.length-2;i>=0;i--) {
right[i] = Math.min(right[i+1], a[i]);
}

int answer = 0;
for(int i=0;i<a.length;i++) {
if(a[i] <= left[i] || a[i] <= right[i])
answer++;
}
return answer;
}
}