✨ 문제https://www.acmicpc.net/problem/10989n개의 수를 입력받아 오름차순으로 정렬하여 출력하는 문제이다.배열에 입력받은 수를 저장하고 Arrays.sort를 사용하여 정렬 후 출력하니 시간초과가 떠서방법을 찾아보던 중 Counting Sort 알고리즘을 알게 되었다. ✨Counting Sort (계수 정렬) 알고리즘- 정렬 알고리즘 중 하나로, 데이터 간의 비교를 하지 않고, 각 데이터의 빈도수를 이용해 정렬한다.- 정수 데이터의 값의 범위가 제한적일 떄 매우 효율적이다.- 동작 방식카운트 배열 초기화데이터가 가질 수 있는 최대값(k)에 따라 크기가 k + 1인 카운트 배열을 생성한다.각 인덱스는 데이터의 특정 값을 나타내고, 해당 인덱스의 값은 데이터에서 그 값이 몇 ..
✨ Java에서 가장 효율적으로 최소값을 찾는 방법알고리즘을 풀면서 여러 정수 중에서 최소값을 구할 수 있는 가장 효율적인 방법을 찾게 되었다.for문으로 직접 비교하는 방법, Stream API를 이용하는 방법, Collection.min()을 사용하는 방법이 있었고, 셋다 시간복잡도는 O(n)으로 동일했다.Arrays.sort로 정렬 후 가장 마지막 인덱스의 값을 가져오는 방법도 괜찮아 보였으나 시간복잡도가 O(nlogn)이어서 제외하였다.근데 시간복잡도는 동일하나, 세가지 방법 중에서 직접 비교하는 방법이 가장 효율적이라고 하여 그 이유에 대해 정리해 보려한다. ✨ for문으로 직접 비교하는 방법public static int findMin(int[] arr) { int min = arr[..
✨ 문제https://www.acmicpc.net/problem/10988알파벳 소문자로 이뤄진 문자열을 입력받아 팰린드롬인지 판별하는 문제이다.팰린드롬인 경우 1, 아닌 경우 0을 리턴해야한다.팰린드롬은 eye처럼 앞으로 읽어도 뒤로 읽어도 똑같은 단어를 말한다. ✨ StringBuilder.reverse()문자열 관련 클래스 중 reverse하는 메소드를 가진 클래스가 있을 것 같아 찾아보니 StringBuilder에 reverse 메소드가 있었다. StringBuffer에도 reverse 메소드가 존재하는데, StringBuffer는 멀티쓰레드에 안전하도록 동기화되어 있는데, 동기화가 성능을 떨어뜨린다. 그래서 멀티쓰레드 프로그램이 아닌 경우에는 StringBuffer에서 동기화만 빠진 Stri..
✨ 문제https://www.acmicpc.net/problem/15552BufferedReader, BufferedWriter를 사용하여 입력값을 받아 출력하는 문제이다.BufferedReader, BufferedWriter를 사용해본 적은 있지만 내가 아는건 Scanner보다 BufferedReader를 사용했을때 속도가 더 빠르다는 점 뿐이고 제대로 된 정의는 잘모르기 때문에 개념을 먼저 공부했다. ✨ BufferedReader와 BufferedWriterBufferedReader는 Reader 클래스를 확장한 것으로 문자 입력 스트림을 버퍼를 사용하여 효율적으로 읽기 위한 클래스이다.마찬가지로 BufferedWriter는 Writer 클래스를 확장한 것으로 문자 출력 스트림을 버퍼를 사용해 효..
✨ 문제 The K Weakes Rows in a Matrix You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.A row i is weaker than a row j if one of the following is true:The number of soldiers in row i is less than the number of soldier..
✨ 문제 Delete Greatest Value in Each RowYou are given an m x n matrix grid consisting of positive integers.Perform the following operation until grid becomes empty:Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them. Add the maximum of deleted elements to the answer.Note that the number of columns decreases by one after each operation.Retur..
✨ 문제 Baseball GamesYou are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.You are given a list of strings operations, where operations[i] is the ith operation you must apply to the record and is one of the following:An integer x.Record a new score of x.'+'Record a new score that is the sum of the previous two scores.'D'Reco..
✨ 문제 Final Prices With a Special Discount in a ShopYou are given an integer array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop. If you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] . Otherwise, you will not receive any discount at all . Retur..
✨ 문제 Number of Recent CallsYou have a RecentCounter class which counts the number of recent requests within a certain time frame.Implement the RecentCounter class:RecentCounter() Initializes the counter with zero recent requests. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 millis..
✨ 문제 Number of Students Unable to Eat LunchThe school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:If the student at..