KEEP GOING!!!!!!!!!!
-
[Programmers] 호텔 방 배정STUDYING/Algorithm 2021. 9. 27. 00:42
https://programmers.co.kr/learn/courses/30/lessons/64063 import Foundation var dict = [Int64: Int64]() func solution(_ k: Int64, _ room_number: [Int64]) -> [Int64] { var answer = [Int64]() for number in room_number { let room = find(room: number) answer.append(room) } return answer } func find(room: Int64) -> Int64 { if dict[room] == nil { dict[room] = room + 1 return room } dict[room] = find(ro..
-
[Programmers] 위장STUDYING/Algorithm 2021. 9. 27. 00:41
func solution(_ clothes:[[String]]) -> Int { var dic: [String: Int] = [:] clothes.forEach { (cloth) in if dic.keys.contains(cloth[1]) { dic[cloth[1]]! += 1 } else { dic[cloth[1]] = 1 } } var result = 1 for val in dic { result *= (val.value + 1) } return result - 1 }
-
[Programmers] 가장 큰 수STUDYING/Algorithm 2021. 9. 27. 00:40
https://programmers.co.kr/learn/courses/30/lessons/42746 import Foundation func solution(_ numbers:[Int]) -> String { let sortedNumbers: [Int] = numbers.sorted { Int("\($0)\($1)")! > Int("\($1)\($0)")! } if sortedNumbers[0] == 0 { return "0" } var numbersStr: [String] = sortedNumbers.compactMap{ String($0) } let res = numbersStr.joined() return res }
-
[Programmers] 실패율STUDYING/Algorithm 2021. 9. 27. 00:39
https://programmers.co.kr/learn/courses/30/lessons/42889 import java.util.Arrays; class Solution { public static int[] solution(int N, int[] stages) { int[] answer = new int[N]; Fail[] tmpAns = new Fail[N]; double[] noClear = new double[N]; for (int stage: stages){ if (stage > N) continue; noClear[stage - 1]++; } double[] player = new double[N]; for (int i = 0; i < N; i++) { if (i == 0) player[0..
-
[Programmers] 가장 먼 노드STUDYING/Algorithm 2021. 9. 27. 00:38
https://programmers.co.kr/learn/courses/30/lessons/49189 import java.util.*; class Solution { public int solution(int n, int[][] edge) { int result = 0; ArrayList[] list = new ArrayList[edge.length]; for(int i = 0; i < n; i++) { list[i] = new ArrayList(); } for (int i = 0; i < edge.length; i++) { int num1 = edge[i][0] - 1; int num2 = edge[i][1] - 1; list[num1].add(num2); list[num2].add(num1); } ..
-
[Programmers] 타겟 넘버STUDYING/Algorithm 2021. 9. 27. 00:37
https://programmers.co.kr/learn/courses/30/lessons/43165 import java.util.*; class Solution { static int answer; public int solution(int[] numbers, int target) { dfs(numbers, target, 0); return answer; } public static void dfs(int[] numbers, int target, int idx) { if (idx == numbers.length) { if (0 == target) answer++; return; } dfs(numbers, target - numbers[idx], idx + 1); dfs(numbers, target +..