본문 바로가기

프로그래머스

프로그래머스 - 올바른 괄호 import java.util.*;class Solution { boolean solution(String s) { Stack savePot = new Stack(); char [] myCharArr = s.toCharArray(); for(char f:myCharArr){ if(f == '('){ savePot.push(f); } else if(f == ')'){ if(savePot.isEmpty()){ return false; } savePot.pop(); .. 더보기
프로그래머스 - 방문 길이 import java.util.*;class Solution { public int solution(String dirs) { int answer = 0; // 중복을 허용하지 않으면 된다! Set checkPass = new HashSet(); int x = 0; int y = 0; for(int i=0; i -5){ String first = "(" + x + "," + y + ")"; x--; String last = "(" + x + "," +y + ")"; String check1 = first + ".. 더보기
프로그래머스 - 행렬의 곱셈 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int first = arr1.length; int second = arr2[0].length; int[][] answer = new int[first][second]; for (int i=0; i 더보기
프로그래머스 - 실패율 import java.util.*;class Solution { public int[] solution(int N, int[] stages) { Map savePot = new HashMap(); // 각 스테이지마다 실패율 계산 후 저장 for (int i = 1; i i) { passCheck++; } } if(passCheck == 0){ savePot.put(i,0.0); } else{ savePot.put(i, failureCheck / passC.. 더보기
프로그래머스 - 두 개 뽑아서 더하기 import java.util.*;class Solution { public int[] solution(int[] numbers) { int[] answer = {}; Set savePot = new HashSet(); for(int i=0; i 더보기
프로그래머스 - 모의고사 import java.util.*;class Solution { public int[] solution(int[] answers) { // 초기값 세팅 int [] first = {1,2,3,4,5}; int [] second = {2,1,2,3,2,4,2,5}; int [] third = {3,3,1,1,2,2,4,4,5,5}; int firstCount = 0; int secondCount = 0; int thirdCount = 0; for (int i=0; i savePot = new ArrayList(); max = Math.max(Math.max(firstCount,secondC.. 더보기