목록알고리즘테스트 (115)
거인의 코딩일지
class Solution { public int solution(int[] a, int[] b) { int answer = 0; int num = 0; for(int i = 0; i < a.length; i++){ num = a[i]*b[i]; answer += num; } return answer; } } 레벨 1인데 뭔가 허무하게 풀었는데 이게 맞는지 정확하게 모르겠지만.... 클리어...!
class Solution { public String solution(int[] food) { String answer = ""; String answer2 = ""; for(int i = 1; i =0; i--){ answer2 += answer.charAt(i); } return answer+"0"+answer2; } } 문제가 길어도 너무 길었지만....! 생각보다 단순하게 풀었다! 우선 answer을 이중for문을 통해서 String으로 형 변환 하여 넣어준뒤! 다시 for ..
class Solution { public int[] solution(int start, int end) { int[] answer = new int[end - start+1]; for(int i =0; i< answer.length; i++){ answer[i] = start; start++; } return answer; } }
Lv.0 이였지만 오랜 생각이 필요한 문제였다...! class Solution { public String solution(String code) { String answer = ""; boolean mode = true; for (int i = 0; i < code.length(); i++) { if (code.charAt(i) == '1') mode = !mode; if ((mode && i % 2 == 0) || (!mode && i % 2 != 0)) { if (code.charAt(i) != '1') answer += code.charAt(i); } } if (answer.isEmpty()) answer = "EMPTY"; return answer; } } 워낙에는 switch - case 문..
import java.util.*; class Solution { public int solution(int[] sides) { int answer = 0; int num = 0; Arrays.sort(sides); num = sides[0]+sides[1] -1; answer = num - (sides[1]-sides[0]); return answer; } } 문제를 보고 패턴을 잘 찾아보닌까 해설에 나와있는 것 마냥 두번 계산할 필요없이 가장 그냥 한번에 num 이라는 변수가 가장 컸을때 를 구해주고 쭉 나열해준뒤 answer변수에 num에서 sides[1] 과 sides[0]을 빼주면 된다. 하지만 여기서 큰수를 정렬시켜주기 위해 오름차순으로 배열을 정리해주었다! 클리어~!
class Solution { public int[] solution(int money) { int[] answer = new int [2]; int num = money / 5500; int result = money%5500; answer[0] = num; answer[1] = result; return answer; } } 심플하게 변수를 설정하고 계산 후 answer 배열 값안에 넣어주었다! 클리어~!
class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; for(int i = 0; i < absolutes.length; i++){ if(signs[i] == false){ absolutes[i] = -1 * absolutes[i]; } answer += absolutes[i]; } return answer; } } for 문을 돌려 그 안에 조건문을 걸어서 fales 라면 absolutes[i] 값에 -1을 곱해준다음 다 더해주었다! 쉽게 풀 수 있었다! 클리어 완료~!
class Solution { public int solution(int n) { int answer = 0; int[] arr = new int[n+1]; arr[0] = 0; arr[1] = 1; for(int i = 2; i
class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr1[1].length]; for(int i =0; i < arr1.length; i++){ for(int j =0 ; j< arr1[i].length; j++){ answer[i][j] =arr1[i][j] + arr2[i][j]; } } return answer; } } 2차원 배열을 덧셈해주면서 느낀건 answer의 크기 설정을 잘 해놔야된다는걸 다시 한번 더 느꼈다.! 클리어~~~