스택/큐 - 프린터
·
Algorithm/프로그래머스
https://programmers.co.kr/learn/courses/30/lessons/42587 코딩테스트 연습 - 프린터 일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린 programmers.co.kr public class Printer { public int solution(int[] priorities, int location) { int answer = 0; // 1. 우선 순위 큐 (큰 수가 우선순위 가짐) PriorityQueue queue = new PriorityQueue(Collections.reverseOrder()); // 2. 우선순위 큐에 ..
검색 알고리즘
·
Algorithm/자료 구조 및 개념 정리
- 검색 알고리즘 : 데이터 집합에서 원하는 값을 가진 요소를 찾아내는 알고리즘 선형검색 - 요소가 직선 모양으로 늘어선 배열에서 원하는 키 값 요소를 만날때까지 맨앞부터 순서대로 요소를 검색하는 것. package basic; import java.util.Scanner; public class SeqSearch { static int seqSearch(int[] a, int n, int key) { // int i = 0; /* while (true) { if (i == n) return -1; if (a[i] == key) return i; i++; } */ for(int i=0; i
정렬 - K번째 수
·
Algorithm/프로그래머스
package programmers.sort; import java.util.Arrays; public class Main { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; // Arrays.copyOfRange(원본배열, 복사할 시작 인덱스, 복사할 끝 인덱스 for (int i = 0; i < commands.length; i++) { int[] arr = Arrays.copyOfRange(array, commands[i][0] - 1, commands[i][1]); Arrays.sort(arr); answer[i] = arr[commands[i][2] -1]; } return..
Lesson2. OddCurrencesInArray
·
Algorithm/Codility
A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2 have value 9, the elements at i..
Lesson2. CyclicRotation
·
Algorithm/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, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that is, each element ..
프로그래머스 - 모의고사
·
Algorithm/프로그래머스
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; class Solution { public int[] solution(int[] answers) { int[][] stdAnswer = {{1, 2, 3, 4, 5}, {2, 1, 2, 3, 2, 4, 2, 5}, {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}}; int[] answerCount = new int[3]; ArrayList studentList = new ArrayList(); for (int i = 0; i < 3; i++..
Lesson1. Binary Gap
·
Algorithm/Codility
https://app.codility.com/programmers/lessons/1-iterations/ 문제 : 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 representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps:..
기본 알고리즘
·
Algorithm/자료 구조 및 개념 정리
알고리즘이란? - 알고리즘: 문제를 해결하기 위한 것으로, 명확하게 정의되고 순서가 있는 유한 개의 규칙으로 이루어진 집합 - 순차적 구조: 여러 문장이 순차적으로 실행되는 구조를 순차적 구조라고 함 - 선택 구조: 식의 평가 결과에 따라 실행 흐름을 변경하는 if문과 같은 구조 import java.util.Scanner; class A { public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); stdIn.nextInt(); } } - 키보드로 숫자와 문자열을 입력하기 위해서는 java.util.Scanner클래스를 프로그램에 포함시키고, - main메서드에 키보드 값을 입력받기 위해 Scanner객체를 생성하여 표..
프로그래머스 - 체육복
·
Algorithm/프로그래머스
체육복을 도난당한 학생의 번호와 여벌이 있는 학생의 번호가 같을 경우를 고려해야하는 문제. def solution(n, lost, reserve): # 체육복을 도난당한 학생이 여벌이 있을경우를 고려하여 둘 다 제거 real_lost = list(set(lost) - set(reserve)) real_reserve = list(set(reserve) -set(lost)) for i in range(len(real_reserve)): if real_reserve[i] -1 in real_lost: real_lost.remove(real_reserve[i] -1) elif real_reserve[i] + 1 in real_lost: real_lost.remove(real_reserve[i] + 1) answ..
takoyummy
'Algorithm' 카테고리의 글 목록 (3 Page)