Algorithm

Algorithm/프로그래머스

[알고리즘] 카운트 다운 Java

import java.util.Arrays; import java.util.Comparator; import java.util.stream.IntStream; class Solution { public int[] solution(int start, int end) { Integer[] ints = IntStream.rangeClosed(end, start).boxed().toArray(Integer[]::new); Arrays.sort(ints, Comparator.reverseOrder()); return Arrays.stream(ints).mapToInt(i -> i).toArray(); } } import java.util.stream.*; import java.util.*; class Soluti..

Algorithm/프로그래머스

[알고리즘] 배열 만들기 1 Java

import java.util.ArrayList; import java.util.List; class Solution { public int[] solution(int n, int k) { List list = new ArrayList(); for (int i = 1; i i % k == 0).toArray(); } }

Algorithm/프로그래머스

[알고리즘] 글자 지우기 Java

import java.util.Arrays; import java.util.stream.Collectors; class Solution { public String solution(String my_string, int[] indices) { String[] split = my_string.split(""); for (int index : indices) { split[index] = ""; } return Arrays.asList(split).stream().collect(Collectors.joining()); } }

Algorithm/프로그래머스

[알고리즘] 문자열 겹쳐쓰기 Java

import java.util.Arrays; import java.util.stream.Collectors; class Solution { public String solution(String my_string, String overwrite_string, int s) { String answer = ""; String[] split = my_string.split(""); for (int i = 0; i < overwrite_string.length(); i++) { split[i+s] = String.valueOf(overwrite_string.charAt(i)); } return Arrays.stream(split).collect(Collectors.joining()); } }

Algorithm/프로그래머스

[알고리즘] 등수 매기기 Java

class Solution { public int[] solution(int[][] score) { int[] answer = new int[score.length]; int ranking = 1; for (int i = 0; i < score.length; i++) { for (int j = 0; j < score.length; j++) { if (score[i][0] + score[i][1] < score[j][0] + score[j][1]) { ranking++; } else if(score[i][0] + score[i][1] == score[j][0] + score[j][1]){ continue; } } answer[i] = ranking; ranking=1; } return answer; } }

Algorithm/프로그래머스

[알고리즘] 로그인 성공? Java

public String solution(String[] id_pw, String[][] db) { int db_size = db.length; for (int i = 0; i < db_size; i++) { if (db[i][0].equals(id_pw[0])) { if(db[i][1].equals(id_pw[1])) { return "login"; } return "wrong pw"; } } return "fail"; }

Algorithm/프로그래머스

[알고리즘] 치킨 쿠폰 Java

class Solution { public int solution(int chicken) { int answer = -1; int coopon = (chicken / 10) + (chicken % 10); answer = chicken / 10; chicken = coopon; while (chicken >= 10) { coopon = (chicken / 10) + (chicken % 10); answer += chicken / 10; chicken = coopon; } return answer; } }

Algorithm/프로그래머스

[알고리즘] 이진수 더하기 Java

class Solution { public String solution(String bin1, String bin2) { return Integer.toBinaryString((Integer.parseInt(bin1, 2)) + Integer.parseInt(bin2, 2)); } } n -> 10진수 String a = "11"; // Binary to Decimal System.out.println(Integer.parseInt(a, 2)); //3 // Octal to Decimal System.out.println(Integer.parseInt(a, 8)); //9 // Hexadecimal to Decimal System.out.println(Integer.parseInt(a, 16)); //1..

rw-
'Algorithm' 카테고리의 글 목록 (12 Page)