본문 바로가기

분류 전체보기148

[Swift] LeetCode - 819. Most Common Word 문제: https://leetcode.com/problems/most-common-word/submissions/ Most Common Word - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com import Foundation class Solution { func mostCommonWord(_ paragraph: String, _ banned: [String]) -> String { var dict = [String: Int]() let words = para.. 2022. 2. 14.
[Swift] LeetCode - 937. Reorder Data in Log Files 문제: https://leetcode.com/problems/reorder-data-in-log-files/ Reorder Data in Log Files - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 처음에 Letter log와 Digits log로 나누는 과정에서 Int($0) != nil 이렇게 검사하였는데 $0의 길이가 너무 크면 분명 숫자밖에 없음에도 Int로 인식하지 않아 틀렸습니다. 따라서 allSatisfy({ $0.isNumber })로 수정.. 2022. 2. 14.
[Swift] 프로그래머스 - 후보키 문제: https://programmers.co.kr/learn/courses/30/lessons/42890 코딩테스트 연습 - 후보키 [["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2 programmers.co.kr 1. 후보키가 될 수 있는 인덱스들을 전부 조합으로 뽑아줍니다. 2. 그 인덱스들이 갖고 있는 값이 중복되지 않는지(유일성) 검사해줍니다. 3. 최소성을 검사합니다. 4. 후보키들을 result 배열에 넣고 카운트를 리턴합니다. im.. 2022. 2. 11.
[Swift] 프로그래머스 - 다단계 칫솔 판매 문제: https://programmers.co.kr/learn/courses/30/lessons/77486 코딩테스트 연습 - 다단계 칫솔 판매 민호는 다단계 조직을 이용하여 칫솔을 판매하고 있습니다. 판매원이 칫솔을 판매하면 그 이익이 피라미드 조직을 타고 조금씩 분배되는 형태의 판매망입니다. 어느정도 판매가 이루어진 후, programmers.co.kr 1. 부모 딕셔너리 만들어서 계속 부모를 찾으며 올라갈 수 있게 하였습니다. 2. 벌어들인 돈은 [이름: 금액] 딕셔너리로 관리하였습니다. 3. 금액의 10%가 1원이 안되면 == 9원 이하면 부모에게 줄 돈이 없으므로 break로 나가게 하였습니다. import Foundation func solution(_ enroll:[String], _ re.. 2022. 2. 11.
[Swift] 프로그래머스 - 예상 대진표 문제: https://programmers.co.kr/learn/courses/30/lessons/12985 코딩테스트 연습 - 예상 대진표 △△ 게임대회가 개최되었습니다. 이 대회는 N명이 참가하고, 토너먼트 형식으로 진행됩니다. N명의 참가자는 각각 1부터 N번을 차례대로 배정받습니다. 그리고, 1번↔2번, 3번↔4번, ... , N-1번↔N programmers.co.kr 첫번째 예시로 설명하면 0번째 라운드 = (1, 2) (3, 4) (5, 6) (7, 8) 이때 a = 4, b = 7 1번째 라운드 = (1, 2) (3, 4) 이때 a = (4 + 1) / 2 = 2, b = (7 + 1) / 2 = 4 2번째 라운드 = (1, 2) 이때 a = (2 + 1) / 2 = 1, b = (4 + .. 2022. 2. 11.
[Swift] 프로그래머스 - 카카오 튜플 문제: https://programmers.co.kr/learn/courses/30/lessons/64065 코딩테스트 연습 - 튜플 "{{2},{2,1},{2,1,3},{2,1,3,4}}" [2, 1, 3, 4] "{{1,2,3},{2,1},{1,2,4,3},{2}}" [2, 1, 3, 4] "{{4,2,3},{3},{2,3,4,1},{2,3}}" [3, 2, 4, 1] programmers.co.kr 차집합은 다른 분의 풀이를 보고 이게 더 깔끔해보이겠다 싶어서 수정하였습니다. import Foundation func solution(_ s:String) -> [Int] { var tuples = s.split(omittingEmptySubsequences: true, whereSeparator: {.. 2022. 2. 11.