알고리즘 풀이/프로그래머스

12345678910111213141516class Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; for(int i=0; i
123456789101112131415161718import java.util.*; class Solution { public String[] solution(String[] strings, int n) { ArrayList arr = new ArrayList(); for (int i = 0; i
12345678910111213141516171819202122class Solution { public String solution(String s, int n) { char[] chArr = s.toCharArray(); for(int i=0; i
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import java.util.*; class Solution { List nodeList; int nodeNum; int answer; boolean[] visited; class Node{ int num; List edge; Node(int num){ this.num = num; edge = new ArrayList(); } } public int solution(int n, int[][] wires) { nodeList = new ArrayLi..
1234567891011121314151617181920import java.util.*; class Solution { public int solution(int[][] sizes) { int a = 0; int b = 0; for(int[] size : sizes){ int lg = Math.max(size[0],size[1]); int sm = Math.min(size[0],size[1]); a = Math.max(a,lg); b = Math.max(b,sm); } return a*b; }} Colored by Color Scriptercs
#2 메모리↓↓ 참고 : https://bangu4.tistory.com/241 참고 안보고는 이런 방식으로 못품 공백을 포함하기 때문에 unit[i] = unit[i+1]*5 +1이라는 공식을 도출을 못낼 것 같음... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution { public int solution(String word) { int answer = word.length(); // char[] alp = new char[]{'A','E','I','O','U'}; String alp = "AEIOU"; int[] unit = new int[]{781,156,31,6,1}; for(int i=0; i
처음에는 백트래킹으로 하려고 했는데 순열을 전부 짜 놓은 다음에 해결하는 것이 훨씬 간편하기도 하고 백트래킹으로 불가능한지 아닌지는 잘 모르겠으나 조건상 어려워 보였음 순열 짜기 -> 짠 순열이 문제에서 주어진 Data(조건)을 전부 만족시키면 answer++(count) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 import java..
12345678910111213141516171819202122232425262728class Solution { public int solution(int[] a) { int len = a.length; if(a.length
#2 Line:7 int*int형을 곱하기전에 제발 둘 중 하나를 long형으로 바꿔줘야 한다고 일단 스스로는 못풀었음 이분탐색이 뭔지는 아는데 구현을 못함 이분탐색 한 10문제정도는 풀어놔야겠음 모든 변수들을 long으로 통일해줘야하고 Line:7의 right값(high값)을 도대체 뭘로 설정해주어아햐는가 맨처음에는 Integer.MAX_VALUE or Long.MAX_VALUE..? 이런거 써야되나 싶었음 진짜 그리고 Line:22부분에 answer=mid 이 부분도 좀 헷갈림 if(mann) else if(man==n) 이렇게 조건문을 3개로 거는 것이 아니고 작은 경우를 제외한 나머지 조건을 else로 빼줘서 아래처럼 처리하면 lower bound를 알아서 찾아주는 메커니즘이 좀 신기했음.. 1 ..
#2 Line:18 & Line:35 Collections.sort( [list] , [Comparator] ) -> list.sort( [Comparator] ); 이렇게 바꾸니까 더 깔끔한 것 같음 핵심은 Map에서는 value값을 이용한 정렬이 불가능하다는 점 key값으로 정렬하고자 하면 treemap으로 바꾸면됨 그 다음에는 문제가 요구하는 조건들 뭔가 이것 저것 조건들이 있어서 처음 보면 어려워보이는데 뜯어 보면 쉬운 문제들이 자잘자잘하게 붙어 있음 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5..
배게
'알고리즘 풀이/프로그래머스' 카테고리의 글 목록 (5 Page)