프로그래머스26 [프로그래머스] 이진수 더하기 class Solution { public String solution(String bin1, String bin2) { String answer = ""; int sum = 0; int binarBin1 = Integer.parseInt(bin1,2); int binarBin2 = Integer.parseInt(bin2,2); sum = binarBin1+binarBin2; answer = String.valueOf(Integer.toBinaryString(sum)); return answer; } } 2진수 표현은 문자열로 가능하다. 2진수>10진수로 만들어서 덧셈연산. 덧셈 결과 sum은 String으로 변환해주고 리턴. 2022. 12. 1. [프로그래머스] 부족한 금액 계산하기 class Solution { public long solution(int price, int money, int count) { long answer = -1; long sum = 0; for(int i=1; imoney){ answer = sum-money; }else { answer = 0; } return answer; } } 2022. 11. 30. [프로그래머스] 개미 군단 class Solution { public int solution(int hp) { int answer = 0; int gAnt = 5; int bAnt = 3; int sAnt = 1; int cnt = 0; int cnt2 = 0; int cnt3 = 0; while(hp!=0){ if(hp>gAnt||hp==gAnt){ cnt = hp/gAnt; hp = hp-(cnt*gAnt); } else if(hpbAnt||hp==bAnt){ cnt2 = hp/bAnt; hp = hp-(cnt2*bAnt); } else{ hp = hp-sAnt; cnt3++; } } answer = cnt+cnt2+cnt3; return answer; } } 2022. 11. 29. [프로그래머스] 나누어 떨어지는 숫자 배열 import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { List temp = new ArrayList(); for(int i=0; i 2022. 11. 29. 이전 1 2 3 4 5 6 7 다음