diff --git "a/jaepyo99/[PGS] \353\263\264\354\204\235 \354\207\274\355\225\221.java" "b/jaepyo99/[PGS] \353\263\264\354\204\235 \354\207\274\355\225\221.java" new file mode 100644 index 000000000..6077bd19c --- /dev/null +++ "b/jaepyo99/[PGS] \353\263\264\354\204\235 \354\207\274\355\225\221.java" @@ -0,0 +1,24 @@ +import java.util.*; +class Solution { + public int[] solution(String[] gems) { + int kind=new HashSet<>(Arrays.asList(gems)).size(); // 주어진 보석의 종류 + int[]answer=new int[2]; //범위를 위한 배열 + int length=Integer.MAX_VALUE,start=0; // length는 진열대의 길이(비교를 위해 큰숫자), start는 진열대의 시작인덱스 + Mapmap=new HashMap<>(); // 선택한 진열대에 있는 각 보석의 개수 + for(int end=0;end1){ // 방금 선택으로 가장 왼쪽에 있는 보석이 여러개가 되었다면 보석의 개수를 줄이기 위해 1감소 + map.put(gems[start],map.get(gems[start])-1); + start++; + } + if(map.size()==kind && length>(end-start)){ + // 현재까지 선택한 진열대에 모든 보석이 있고, 길이가 짧다면 인덱스 업데이트 + length=end-start; + answer[0]=start+1; + answer[1]=end+1; + } + } + // for문을 통해 가장 왼쪽에서 보석의 종류가 채워지는 최초의 배열을 찾은뒤, 이후의 조합중에 개수가 더 적은 배열이 있는지 찾는 방식 + return answer; + } +} diff --git "a/jaepyo99/[PGS] \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.java" "b/jaepyo99/[PGS] \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.java" new file mode 100644 index 000000000..e976342b0 --- /dev/null +++ "b/jaepyo99/[PGS] \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.java" @@ -0,0 +1,49 @@ +import java.util.*; +class Solution { + int answer; + Set>ans_set=new HashSet<>(); + String[]userIds; + String[]banIds; + public boolean isBan(String user,String ban){ + if(user.length()!=ban.length()){ + return false; + } + for(int i=0;iset,int depth){ + if(depth==banIds.length){ + ans_set.add(set); + return; + } + for(int i=0;i(set),depth+1); + set.remove(userIds[i]); + } + } + } + + + public int solution(String[] user_id, String[] banned_id) { + answer = 0; + boolean[]visit_user=new boolean[user_id.length]; + userIds=user_id; + banIds=banned_id; + dfs(new HashSet<>(),0); + + return ans_set.size(); + } +} diff --git "a/jaepyo99/[PGS] \354\210\253\354\236\220 \352\262\214\354\236\204.java" "b/jaepyo99/[PGS] \354\210\253\354\236\220 \352\262\214\354\236\204.java" new file mode 100644 index 000000000..177d499f5 --- /dev/null +++ "b/jaepyo99/[PGS] \354\210\253\354\236\220 \352\262\214\354\236\204.java" @@ -0,0 +1,32 @@ +// 이기면 승점1 +// 최대 승점을 계산하시오 +// A는 A팀의 출전 순서 +// B는 B팀의 번호목록 + +// A팀의 순서가 의미가 있나? +// 5 1 3 7 +// 2 2 6 8 / 0,3 +import java.util.*; +class Solution { + boolean[]visit; + int max=0; + public int solution(int[] A, int[] B) { + Arrays.sort(A); + Arrays.sort(B); + int a=0; + int b=0; + int result=0; + for(int i=0;iB[b]){ + b++; + }else if(A[a]==B[b]){ + b++; + }else{ + a++; + b++; + result++; + } + } + return result; + } +} diff --git "a/jaepyo99/[PGS] \354\212\244\355\213\260\354\273\244 \353\252\250\354\234\274\352\270\260(2).java" "b/jaepyo99/[PGS] \354\212\244\355\213\260\354\273\244 \353\252\250\354\234\274\352\270\260(2).java" new file mode 100644 index 000000000..0c43ba9ea --- /dev/null +++ "b/jaepyo99/[PGS] \354\212\244\355\213\260\354\273\244 \353\252\250\354\234\274\352\270\260(2).java" @@ -0,0 +1,28 @@ +import java.util.*; +class Solution { + int max=0; + public int solution(int sticker[]) { + int answer = 0; + int l=sticker.length; + int[]arr=new int[l]; + if(l==1){ + return sticker[0]; + } + int[]dp=new int[l]; + dp[0]=sticker[0]; + dp[1]=dp[0]; + for(int i=2;ipq=new PriorityQueue<>(); + for(int i=0;i0){ + // System.out.println("==="); + n--; + cm=0; + for(int i=0;i0){ + time=changeTime(time,t); + } + // System.out.println("time : "+time); + // System.out.println("lastTimeTable : "+lastTimeTable); + + } + if(cm=1;i--){ + for(int j=0;j+i<=n;j++){ + if(isPal(s,j,i+j-1)){ + return i; + } + } + } + return 0; + } + public boolean isPal(String s,int start,int end){ + while(start<=end){ + if(s.charAt(start++)!=s.charAt(end--)){ + return false; + } + } + return true; + } +} diff --git "a/jaepyo99/[PGS]\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.java" "b/jaepyo99/[PGS]\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.java" new file mode 100644 index 000000000..53be20bf7 --- /dev/null +++ "b/jaepyo99/[PGS]\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.java" @@ -0,0 +1,71 @@ +import java.util.*; +class Solution { + static class Point{ + int x,y,dir,cost; + Point(int x,int y,int dir, int cost){ + this.x=x; + this.y=y; + this.dir=dir; + this.cost=cost; + } + } + static boolean[][] visit; + static int answer; + static int n; + static int[][][]arr; + public int solution(int[][] board) { + answer=Integer.MAX_VALUE; + n=board.length; + arr=new int[4][n][n]; + for(int i=0;i<4;i++){ + for(int x=0;xq=new LinkedList<>(); + q.add(new Point(x,y,dir,cost)); + visit[x][y]=true; + while(!q.isEmpty()){ + Point point=q.poll(); + int px=point.x; + int py=point.y; + int pdir=point.dir; + int pcost=point.cost; + if(px==n-1 && py==n-1){ + answer=Math.min(answer,pcost); + continue; + } + for(int i=0;i<4;i++){ + int nx=px+dx[i]; + int ny=py+dy[i]; + int ndir=i; + int ncost=pcost; + if(nx<0 ||nx>=n||ny<0||ny>=n||board[nx][ny]==1){ + continue; + } + if(pdir==-1){ + ncost+=100; + }else if(pdir==ndir){ + ncost+=100; + }else{ + ncost+=600; + } + + if(!visit[nx][ny] || arr[ndir][nx][ny]>=ncost){ + visit[nx][ny]=true; + arr[ndir][nx][ny]=ncost; + q.add(new Point(nx,ny,ndir,ncost)); + } + } + } + } +} diff --git "a/jaepyo99/[PGS]\352\270\260\354\247\200\352\265\255 \354\204\244\354\271\230.java" "b/jaepyo99/[PGS]\352\270\260\354\247\200\352\265\255 \354\204\244\354\271\230.java" new file mode 100644 index 000000000..c65cdd6fe --- /dev/null +++ "b/jaepyo99/[PGS]\352\270\260\354\247\200\352\265\255 \354\204\244\354\271\230.java" @@ -0,0 +1,20 @@ +import java.util.*; +class Solution { + public int solution(int n, int[] stations, int w) { + int answer=0; + Queuequeue=new LinkedList<>(); + int idx=0; + int now=1; + int l=stations.length; + while(now<=n){ + if(idx(){ + @Override + public int compare(int[]o1,int[]o2){ + if(o1[0]==o2[0]){ + return o1[1]-o2[1]; + }else{ + return o1[0]-o2[0]; + } + } + }); + // for(int i=0;i=0){ + if(visit[y][x-1]>0){ + xv=visit[y][x-1]; + }else{ + xv=dynamic(x-1,y); + } + } + if(y-1>=0){ + if(visit[y-1][x]>0){ + yv=visit[y-1][x]; + }else{ + yv=dynamic(x,y-1); + } + } + if(x==0 && y==0){ + return 1; + } + visit[y][x]=(xv+yv)%1000000007; + return (xv+yv)%1000000007; + } + public int solution(int m, int n, int[][] puddles) { + visit=new int[n][m]; + for(int i=0;i pq = new PriorityQueue<>(Collections.reverseOrder()); + for(int i=0;iMAX){ + MAX=dp1[i]; + } + if(dp2[i]>MAX){ + MAX=dp2[i]; + } + } + + return MAX; + } +} diff --git "a/jaepyo99/[PGS]\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.java" "b/jaepyo99/[PGS]\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.java" new file mode 100644 index 000000000..c94917a21 --- /dev/null +++ "b/jaepyo99/[PGS]\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.java" @@ -0,0 +1,13 @@ +class Solution { + public int solution(int[][] triangle) { + int answer = 0; + int r=triangle.length; + for(int i=r-1;i>0;i--){ + int c=triangle[i].length; + for(int j=0;j