본문 바로가기

CodingTest/Programmers81

Lv.0 모음제거 ** class Solution { public String solution(String my_string) { String []strarr = my_string.split(""); String []collarr = {"a","e","i","o","u"}; StringBuilder sb = new StringBuilder(); for (int i = 0; i < strarr.length; i++) { boolean flag = false; for (int j = 0; j < collarr.length; j++) { if (strarr[i].equals(collarr[j])) { flag = true; } } if(flag==false) sb.append(strarr[i]); } return sb.toStrin.. 2022. 11. 23.
Lv.0 문자열안에 문자열 class Solution { public int solution(String str1, String str2) { return str1.contains(str2) ? 1:2; } } String클래스의 contains메소드를 이용해서 구하기 2022. 11. 22.
Lv.0 옷가게 할인 받기 class Solution { public int solution(int price) { double answer = 0; if(price>=100000&&price=300000&&price=500000)answer = price*0.8; else answer = price; return (int)answer; } } 조건을 잘 생각해서 넣어주자. 2022. 11. 22.
Lv.0 제곱수 판별하기 * class Solution { public int solution(int n) { int answer = 2; for(int i=2; i 2022. 11. 22.
Lv.0 순서쌍의 개수 class Solution { public int solution(int n) { int answer = 0; for(int i=1; i 2022. 11. 22.
Lv.0 자릿수 더하기 class Solution { public int solution(int n) { int answer = 0; while(n>0){ answer += n%10; n/=10; } return answer; } } 길이가n인 정수에서 한글자씩 봐야할 때 String[] 으로 만들어서 for문을 이용해 Integer.paresInt()를 사용해도 좋지만 n%10과 n/10을 이용하는 방법이 더 빠르고 String으로 변환할 필요가 없어서 실수가 적다. 2022. 11. 22.
Lv.0 배열의 유사도 class Solution { public int solution(String[] s1, String[] s2) { int answer = 0; for(int i=0; i 2022. 11. 22.
Lv.0 짝수는 싫어요 import java.util.ArrayList; class Solution { public int[] solution(int n) { ArrayList answer = new ArrayList(); for(int i=0; i 2022. 11. 22.
Lv.0 아이스 아메리카노 class Solution { public int[] solution(int money) { int[] answer = new int[2]; answer[0] = money/5500; answer[1] = money%5500; return answer; } } 몫이 살 수 있는 잔의 수가 되고 나머지가 잔돈이 된다. 2022. 11. 22.
728x90
반응형