본문 바로가기

프로그래머스/JAVA21

[스택/큐] 쇠막대기 1234567891011121314151617181920212223242526272829303132import java.util.Stack; public class Stick { public int solution(String arrangement) { int answer = 0; char []pipe=arrangement.toCharArray(); Stacklazer=new Stack(); return getPipeNumber(answer, pipe, lazer); } //잘려진 파이프 조각 갯수세는 메소드 public int getPipeNumber(int answer, char[] pipe, Stack lazer) { for(int i=0;i 2018. 12. 28.
[스택/큐] 타워 1234567891011121314151617181920212223242526272829public class Tower { public int[] solution(int[] heights) { int [] answer=new int[heights.length];//정답의 배열 크기는 타워의 갯수랑 같다 boolean checkHeight=false; int index=0; for(int i=0;i=0;j--){//왼쪽으로 신호를 보내기 때문 if(heights[i] 2018. 11. 2.
[우선순위 큐] 더 맵게 123456789101112131415161718192021222324252627282930313233import java.util.PriorityQueue; public class Scoville { public int solution(int[] scoville, int K) { int answer = 0; PriorityQueue scoInfo = new PriorityQueue(scoville.length); addElement(scoville, scoInfo); return getAnswer(K, answer, scoInfo); } public int getAnswer(int K, int answer, PriorityQueue scoInfo) { int tempSco; while (scoInfo... 2018. 10. 24.
[level 2] 124 나라의 숫자 123456789101112131415161718192021public class oneTwoFour { public String solution(int n) { StringBuilder answer = new StringBuilder(); int []countryNumber={4,1,2}; change124(n, answer, countryNumber); return answer.reverse().toString();//뒤에다 추가해서 reverse()했다. } private void change124(int n, StringBuilder answer, int[] countryNumber) { int check; while (n>0){ check=n%3;//나머지 n=n/3;//몫 if (check==.. 2018. 10. 17.