본문 바로가기
320x100
728x90

알고리즘6

프로그래머스,java]Level2 기능개발 순서가 바뀌면 안 되는 작업 진척률 progresses와 speeds를 반복문을 돌며 앞 인덱스가 다 되어야 배포를 하는 방식이다. 반복문을 돌면서 진척률이 100이 되었다면 100 인애들 다 앞에서부터 배포하고 100이 안됐다면 speeds만큼 더하면 된다. 👨🏻‍💻나의 풀이 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { ArrayList list = new ArrayList(); int index = 0; while (true) { int count = 0; if (progresses[index] >= 100) { for (int i = index; i < progresses.len.. 2022. 2. 19.
문자열 압축 [java] 입력받은 문자열을 압축하는 알고리즘 (중복되는 개수만큼 우측에 숫자로 표현) 입력 예: KKKSSERRHEEK 출력 예 : K4S2E3R2H package com.wesley; public class Main { public static void main(String[] args) { System.out.println(shrots("KKKSSERRHEEK")); } public static String shrots(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { if (sb.toString().contains(String.valueOf(input.charAt(i)))) { co.. 2021. 10. 24.
java,알고리즘] 문자열에서 숫자만 추출하기 입력받은 문자열에서 숫자만 추출하여 int형으로 리턴하기. 입력 예 : 0sads21a0w8ws87 출력 예 : 210887 내가 풀었던 방법 1: public class Main { public static void main(String[] args) { Main main = new Main(); System.out.println(main.find("0sads21a0w8ws87")); } public int find(String input) { StringBuilder sb = new StringBuilder(); int length = input.length(); for (int i = 0; i < length; i++) { try { sb.append(Integer.parseInt(String.va.. 2021. 10. 5.
java] 회문 문자열 체크(팰린드롬) 회문 문자열이란? 앞으로 읽거나 뒤로 읽어도 같은 문자임을 뜻한다. ex:) abcba goodoog 예를 들면 이런 문자들이다. 입력받은 문자열이 회문 문자열임을 체크하는 알고리즘 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("회문 문자열 체크"); System.out.println(solution(sc.nextLine().toUpperCase())); } public static boolean solution(String input) { return input.equals(new StringBuilder(input).reverse().to.. 2021. 9. 6.
300x250
320x100