
https://school.programmers.co.kr/learn/courses/30/lessons/12931 문제 사진 내 풀이 func solution(_ n:Int) -> Int { return String(n).map { Int(String($0))! }.reduce(0) { $0 + $1 } } solution(340) 처음엔 파라미터로 들어오는 n을 String 변환 후 split(separate: "") 로 진행했으나, character로 되는점에서 그냥 map 을 사용한 후 Int(String($0))으로 풀어내는게 더 직관적이라 생각해서 바꿨다. 다른사람의 풀이 import Foundation func solution(_ n:Int) -> Int { return String(n).re..

https://school.programmers.co.kr/learn/courses/30/lessons/70128 내 풀이 import Foundation func solution(_ a:[Int], _ b:[Int]) -> Int { var saveArr: [Int] = [] for (idx, num) in b.enumerated() { saveArr.append(num * a[idx]) } let result: Int = saveArr.reduce(0, { $0 + $1}) return result } solution([1,2,3,4], [-3,-1,0,2]) 다른사람의 풀이 func solution(_ a:[Int], _ b:[Int]) -> Int { let result = zip(a, b).ma..

알고리즘 문제 URL https://school.programmers.co.kr/learn/courses/30/lessons/12925?language=swift 문제 사진 내 풀이 func solution(_ s:String) -> Int { guard let result = Int(s) else { return 0 } return result } 다른사람의 풀이 func solution(_ s:String) -> Int { return Int(s)! } 배운것 String → Int로 변환하기 위해 Int( ) 메서드를 사용합니다. String의 경우 아래와 같이 Int로 변환할 수 없을 가능성도 있기 때문에 Optional 처리가 되어 결과값이 나옵니다. Int(" 100") // Includes ..

https://school.programmers.co.kr/learn/courses/30/lessons/86051 문제 사진 내 풀이 0부터 9까지의 총합은 45니까 45 - numbers 내부의 있는 총합 으로 답을 구했다. func solution(_ numbers:[Int]) -> Int { return 45 - numbers.reduce(0, +) } 다른사람의 풀이 func solution(_ numbers:[Int]) -> Int { let result = (0...9) .filter { !numbers.contains($0) } .reduce(0) { $0 + $1 } return result }

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3240/discuss/234202/Swift-no-brainer 내 풀이 func sortedSquares(_ nums: [Int]) -> [Int] { return nums.map { ($0 * $0) }.sorted() } sortedSquares([-7,-3,2,3,11]) 배운것 sorted(by:) 요소(elements)들 간의 비교로 정렬을 해줍니다. 예제 let numArr = [-7,-3,2,3,11] print(numArr.sorted()) // 오름차순 // [-7, -3, 2, 3, 11] print(numArr.sorted(by: >)) // 내림차순 ..

[Swift 알고리즘] - Find Numbers with Even Number of Digits(Leetcode) https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 내 풀이 class Solution { func ..

https://programmers.co.kr/learn/courses/30/lessons/67256 코딩테스트 연습 - 키패드 누르기 [1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL" programmers.co.kr 내 풀이 머리를 굴려봤지만 포기.. 로.직.폭.망 로직보기 더보기 func solution(_ numbers:[Int], _ hand:String) -> String { var lhs = -1 var rhs = -2 var lhsDistance = 0 ..

https://programmers.co.kr/learn/courses/30/lessons/12930 코딩테스트 연습 - 이상한 문자 만들기 문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 programmers.co.kr 내 풀이 func solution(_ s: String) -> String { var arr: [String] = [] var count = 0 for char in s { if count == 0 || count % 2 == 0 { arr.append(char.uppercased()) } else { arr.append(char.lowercased..

https://programmers.co.kr/learn/courses/30/lessons/12943 코딩테스트 연습 - 콜라츠 추측 1937년 Collatz란 사람에 의해 제기된 이 추측은, 주어진 수가 1이 될때까지 다음 작업을 반복하면, 모든 수를 1로 만들 수 있다는 추측입니다. 작업은 다음과 같습니다. 1-1. 입력된 수가 짝수라면 2 programmers.co.kr 내 풀이 func solution(_ num:Int) -> Int { var count = 0 var number = num let noResult = -1 while number != 1 { if number % 2 == 0 { number = number / 2 count += 1 } else if number % 2 == 1 ..

https://programmers.co.kr/learn/courses/30/lessons/12926 코딩테스트 연습 - 시저 암호 어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식을 시저 암호라고 합니다. 예를 들어 "AB"는 1만큼 밀면 "BC"가 되고, 3만큼 밀면 "DE"가 됩니다. "z"는 1만큼 밀 programmers.co.kr 내 풀이 못 푼 문제 못 푼 문제는 주말에 복습! 다른사람의 풀이 func solution(_ s: String, _ n: Int) -> String { let alphabets = "abcdefghijklmnopqrstuvwxyz".map { $0 } return String(s.map({ guard let index = alpha..
- Total
- Today
- Yesterday
- Swift Error Handling
- Swift RIBs
- Swift ModernRIBs
- Swift
- swift programmers
- RIBs tutorial
- Swift joined
- 2023년 회고
- swift protocol
- swift 고차함수
- Class
- Swift final
- Swift inout
- CS 네트워크
- removeLast()
- swift (programmers)
- Swift init
- Swift Leetcode
- Swift 알고리즘
- RTCCameraVideoCapturer
- Swift 내림차순
- iOS error
- swift property
- Swift 프로퍼티
- ios
- 원티드 프리온보딩
- Swift joined()
- Combine: Asynchronous Programming with Swift
- swift reduce
- Swift 프로그래머스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |