Algorithm

    [프로그래머스] 상호 평가

    https://programmers.co.kr/learn/courses/30/lessons/83201 코딩테스트 연습 - 2주차 [[100,90,98,88,65],[50,45,99,85,77],[47,88,95,80,67],[61,57,100,80,65],[24,90,94,75,65]] "FBABD" [[70,49,90],[68,50,38],[73,31,100]] "CFD" programmers.co.kr 상호 평가로 학생들에게 점수를 부여한다. 자신에게 부여한 점수가 유일한 최고점 혹은 유일한 최저점일 경우 제외 시키고 그 외에는 모두 합산하여 평균을 구하고 문자열로 점수를 반환하시오. class Solution { public String solution(int[][] scores) { String ..

    [LeetCode] - How Many Numbers Are Smaller Than the Current Number

    brute force => 500 ^ 500 => 25000 성능상으로 느리진 않을거 같긴함 brute force 말고 위치기억 sorting? 순회하면서 나머지 비교 selection sort 생각을 해봅시다 주어진 nums배열을 두고 배열을 복사한다. space complexity O(N) 복사한 배열을 sorting time complexity O(N) X => tim sort -> O(n log n) Map key는 음 계수정렬을 써볼까 어짜피 0 ~ 100 공간만 있으면 됌 import java.util.*; class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { int numsCount = nums.length; int[] ..

    [프로그래머스] - 로또의 최고 순위와 최저 순위

    https://programmers.co.kr/learn/courses/30/lessons/77484 코딩테스트 연습 - 로또의 최고 순위와 최저 순위 로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호 programmers.co.kr import java.util.*; class Solution { public int[] solution(int[] lottos, int[] win_nums) { /* 1. 0 분리 -> 2개 배열 space complexity 2. sort each int arrays 3. check 3-1 lottos[i] ==..

    [LeetCode] Max Consecutive Ones

    0과 1로 이루어진 nums 배열에서 연속된 1이 가장 많이 이어졌을때 수를 반환하시오 class Solution { public int findMaxConsecutiveOnes(int[] nums) { /* 이진 배열인 nums가 주어졌을때, 연속된 1의 최대수를 반환하시오. 1 = maximum) maximum = temp; } return maximum; } } Runtime: 1 ms, faster than 100.00% of Java online submissions for Max Consecutive Ones. Memory Usage: 40.2 MB, less than 76.94% of Java online submissions for Max Consecutive Ones.

    [LeetCode] Minimum Number of Operations to Move All Balls to Each Box

    You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes. Return an array answer of size n, where answer[i] is the min..

    [LeetCode] Jewels and Stones

    You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". Example 1: Input: jewels = "aA", stones = "aAAbbbb" Output: 3 Example ..