알고리즘
-
최댓값 최솟값 찾기알고리즘/프로그래머스 2020. 9. 22. 11:30
문제 : 문자열 s에는 공백으로 구분된 숫자들이 저장되어 있습니다. str에 나타나는 숫자 중 최소값과 최대값을 찾아 이를 (최소값) (최대값)형태의 문자열을 반환하는 함수, solution을 완성하세요. 예를들어 s가 1 2 3 4라면 1 4를 리턴하고, -1 -2 -3 -4라면 -4 -1을 리턴하면 됩니다.제한 조건 s에는 둘 이상의 정수가 공백으로 구분되어 있습니다. 입출력 예 sreturn 1 2 3 4 1 4 -1 -2 -3 -4 -4 -1 -1 -1 -1 -1 https://programmers.co.kr/learn/courses/30/lessons/12939 package com.programmers; import java.util.Arrays; public class FindMinMaxNu..
-
문제 23번 - 문자열 거꾸로 출력.알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:30
문제 : 입력된 문자열 거꾸로 출력하기 예) ADEFH -> HFEDA import java.util.*; class Youtube23 { public static void main(String[] args){ String checkStr = new Scanner(System.in).next(); String reverseStr = new StringBuffer(checkStr).reverse().toString(); System.out.println(reverseStr); /* 강의 정답. String n = "ADEFH"; char str[] = n.toCharArray(); char tmp; int len = str.length; for(int i=0; i
-
문제 22번 - 팬린드롬알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:29
문제 : 팬린드롬인지 판별 * 팬린드롬 : 거꾸로 읽어도 같은 문장 예) 12321 -> true import java.util.*; class Youtube22 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int num = sc.nextInt(); String parseNum = String.valueOf(num); String reverseStr = new StringBuffer(parseNum).reverse().toString(); if(parseNum.equals(reverseStr)){ System.out.println(true); }else{ System.out.println(false); } /..
-
문제 21번 - 중복된 수 제거 후 출력알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:25
import java.util.*; public class Youtube21 { public static void main(String[] args){ /* List resultList = new ArrayList(); System.out.println("if you stop program, input 0"); Scanner scanner = new Scanner(System.in); while(true){ int number = scanner.nextInt(); if(number == 0){ for(int result : resultList){ System.out.print(result + " "); } break; } if(1
-
MissingInteger알고리즘/Codility 2020. 9. 13. 21:32
이 문제는 내가 푼 답이 맞긴 했지만, 답 확인 할때 시간이 오래걸려서 통과 하지 못했었다. 결국 다른 사람의 풀이를 보고 통과할 수 있었는데 정말 어떻게 이렇게 생각해서 푸는지 다양한 문제를 더 많이 풀어봐야겠다ㅠㅠ https://app.codility.com/demo/results/trainingDZ8W4Q-Z7Y/ Test results - Codility A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary ..
-
CyclicRotation알고리즘/Codility 2020. 9. 13. 21:24
app.codility.com/demo/results/training8K9DTZ-447/ Test results - Codility An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, app.codility.com 문제) 배열 A의 값을 K만큼 우측으로 이동시켜 출력. 마지막 배열의 값은 배열의 첫번째로..
-
BinaryGap알고리즘/Codility 2020. 9. 13. 21:13
문제) 정수 N에서 binaryGap의 최댓값을 찾아라. binaryGap이란 1로 둘러쌓인 0의 개수로, 예) N이 529일때, 2진수로는 1000010001 이때, binaryGap의 최댓값은 4. binaryGap이 없으면 return -1; 나의 해답 import java.util.*; class Solution { public int solution(int N) { int answer = 0; if(N == 1 || N == 0){ return answer; } int mok = 0; List list = new ArrayList(); while (mok != 1) { mok = (N / 2); list.add((N % 2)); if (mok == 1) { list.add(mok); } N = ..