본문 바로가기

swift64

💯 Daily LeetCode Challenge Day_09 - Maximum Width of Binary Tree 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 문제 Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the sam.. 2020. 7. 9.
Swift - BFS iteration on Binary Tree [1,3,2,5,3,null,9] func bfs(_ root: TreeNode?) -> Int { if root == nil { return 0 } var maxWidth = 0 var queue : [TreeNode] = [] queue.append(root!) while(!queue.isEmpty){ var count = queue.count maxWidth = max(maxWidth,count) while(count > 0){ var tmp = queue.removeFirst() print(tmp.val) if(tmp.left != nil){ queue.append(tmp.left!) } if(tmp.right != nil){ queue.append(tmp.right!) } count -= 1 }.. 2020. 7. 9.
Swift enum - 열거형 Enum : 열거형 연관된 항목들을 묶어서 표현 딱 정해진 값만 열거형 값에 속할 수 있음 각 열거형이 고유의 타입으로 인정됨 제한된 선택지를 주고싶을 때 정해진 값 외에는 입력받고 싶지 않을 때 예상된 입력 값이 한정되어 있을 때 enum Apple { case Macbook case MacbookPro case iPad case iPadPro case iPhone11 case iPhone11Pro case appleWatch } var device : Apple = Apple.iPad var device : Apple = .iPad //change value device = .iPadPro enum 은 원시값도 가질 수 있다. enum Apple { case Macbook = "맥북" case Mac.. 2020. 7. 9.
💯 Daily LeetCode Challenge Day_08 - 3Sum Account Login - 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 문제 Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate tri.. 2020. 7. 9.
RxSwift: Hello RxSwift!🖐 What is RxSwift? library for composing asynchronous and event-based code by using observable sequences and functional style operators, allowing for parameterized execution via schedulers simplifies developing asynchronous programs by allowing your code to react to new data and process in a sequential, isolated manner 왜 RxSwift 가 필요한가 parallel 한 코드를 작성하는 건 원래 힘들지만 특히 같은 데이터를 이용하는 병렬 코드를 작성하는건 정말 .. 2020. 7. 8.
💯 Daily LeetCode Challenge Day_07 - Island Perimeter Account Login - 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 문제 You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by w.. 2020. 7. 7.
💯 Daily LeetCode Challenge Day_06 - Plus One Account Login - 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 문제 Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array co.. 2020. 7. 7.
Swift 알고리즘에 쓰이는 문법 정리 String 특정 기준으로 나누기 String -> [String] : components var str = "12345678" var arr = str.components(separatedBy : "5") //["1234","678"] String 빈칸 없애기 or 문자 치환 : replacingOccurrences var str = "1 2 3 4 5" let replaced = str.replacingOccurrences(of: " ", with: "") //"12345" String -> [String] : Array var str = "123 45" var arr = Array(str) //["1","2","3"," ","4","5"] [Int] -> [String] : map //digits .. 2020. 7. 7.
💯 Daily LeetCode Challenge Day_05 - Hamming Distance 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 문제 The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming di.. 2020. 7. 6.
💯 Daily LeetCode Challenge Day_04 - Ugly Number II Account Login - 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 문제 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example: Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence.. 2020. 7. 6.
💯 Daily LeetCode Challenge Day_03 - Prison Cells After N Days 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 문제 There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the following rules.. 2020. 7. 3.
💯 Daily LeetCode Challenge Day_02 - Binary Tree Level Order Traversal II Account Login - 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 문제 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). level 에 맞게 2개씩 짝짓는다. DFS 로 풀다가 트리의 depth 별로 접근하니 BFS 인가 싶어서 Queue를 쓰는.. 2020. 7. 3.
💯 Daily LeetCode Challenge Day_01 - Arranging Coins Account Login - 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 문제 You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative i.. 2020. 7. 1.
Swift 코딩 테스트 준비 - Java to Swift 😱 이번에 하계 인턴을 위한 코테를 칠 예정이다. 오늘 안내 메일을 받았는데 세상에나 Swift 언어만 지원한다고 한다. iOS직군이라 그런것 같으나 언어 제한을 둘 줄은 몰랐다. 평소에 Swift로 슬슬 풀어볼까 생각이 들었었는데 이 참에 Swift로 풀어야 겠다. 🤦‍♂️ 문자열 - 가운데 수 찾기 func solution(_ s:String) -> String { if(s.count%2==0){ let index1 = s.index(s.startIndex, offsetBy: s.count/2-1) let index2 = s.index(s.startIndex, offsetBy: s.count/2) return "\(s[index1])\(s[index2])" }else{ let index1 = s.inde.. 2020. 7. 1.
RxSwift를 사용한 비동기 프로그래밍 #3 https://github.com/iamchiwon iamchiwon - Overview https://iamchiwon.github.io http://www.makecube.in - iamchiwon github.com 기획서만 나오고 디자인과 백엔드가 나오기 전에 개발해보자 [기획내용] 메뉴 + - count 요소 메뉴에는 이름과 가격이 있다. clear 로 전부 취소할 수 있다. 전체 가격을 표시할 수 있다. 등등 1. ViewModel 을 만든다. import Foundation // View를 위한 모델 : ViewModel struct Menu { var name : String var price : Int var count : Int } 2. TableVIew 에 ViewModel 을 집어넣.. 2020. 5. 29.
RxSwift를 사용한 비동기 프로그래밍 #2 iamchiwon/RxSwift_In_4_Hours RxSwift, 4시간 안에 빠르게 익혀 실무에 사용하기. Contribute to iamchiwon/RxSwift_In_4_Hours development by creating an account on GitHub. github.com [2교시] RxSwift 활용하기 - 쓰레드의 활용과 메모리 관리 Stream의 분리 및 병합 [merge] ReactiveX - Merge operator RxScala implements this operator as flatten, flattenDelayError, merge, and mergeDelayError. merge takes a second Observable as a parameter and merge.. 2020. 5. 28.
RxSwift를 사용한 비동기 프로그래밍 #1 iamchiwon/RxSwift_In_4_Hours RxSwift, 4시간 안에 빠르게 익혀 실무에 사용하기. Contribute to iamchiwon/RxSwift_In_4_Hours development by creating an account on GitHub. github.com [1교시] 개념잡기 - RxSwift를 사용한 비동기 프로그래밍 textview 에 json 데이터를 띄우는 함수 버튼을 누르면 animation이 실행된다. @IBAction func onLoad() { editView.text = "" setVisibleWithAnimation(activityIndicator, true) let url = URL(string: MEMBER_LIST_URL)! let data = tr.. 2020. 5. 27.
CoreML 배워보자 (2) - Object Detection 실전! Core ML을 활용한 머신러닝 iOS 앱 개발: 인공지능을 활용한 객체 인식, 감정 탐지, 스타일 전이, 스케치 인식 구현 애플 Core ML을 활용한 스마트한 iOS 앱 만들기! Core ML은 다양한 머신러닝 작업을 지원하기 위해 설계된 API를 제공하는 애플의 유명한 프레임워크다. 이 프레임워크를 활용하면 머신러닝 모델을 훈련시킨 다음 그 모델을 iOS 앱에 통합시킬 수 있다. 이 책은 Core ML을 이해하기 쉽게 설명할 뿐 아니라 머신러닝을 명확하게 설명해 준다. 모바일 플랫폼(특히 iOS)에서 현실적이면서 흥미로운 머신러닝 예제를 통해 배우며, 시각 기반의 애플리케 wikibook.co.kr CoreML 배워보자 (1) 책을 한권 샀다. 실전! Core ML을 활용한 머신러닝 iOS .. 2020. 4. 24.
iOS 오픈소스 라이브러리 만들기 101 오픈소스 라이브러리 만들기 - 야곰닷넷 코코아팟(CocoaPods), 카르타고(Carthage), 스위프트 패키지 매니저(Swift Package Manager, SPM)를 활용하여 나만의 오픈소스 라이브러리(Open Source Library)를 만들어봅니다. yagom.net 오픈소스 라이브러리를 만들어 볼까 한다. 내용은 안드로이드를 개발한 뒤 iOS를 개발하면서 없어서 불편했던 위젯이나 기능들을 위주로 개발하려고 한다. 유용하고 쓸모있고 없고를 떠나서 오픈소스를 만들어 보겠다는 마음이 중요한 것 아니겠나?! (아니면 말고,,,) 먼저 개발해보려 간단하게 생각했던건 Toast CheckBox RatingStar radio button radio group floating action button 이.. 2020. 4. 18.
iOS 유닛 테스트를 배워보자!(1) 시작에 앞서 개인적으로 학과 수업을 통해 소프트웨어 개발에서 테스트의 중요성은 알고 있었지만 실제 개발에 어떻게 적용해야 하는지 모르는 상태였다. 마침 2019 GDG 부산 행사에서 DevOps 와 Testing 에 관한 세션이 있었고 그때 구체적으로 TDD 가 무엇인지 알게 되었다. https://festa.io/events/557 GDG Devfest Busan 2019💖 | Festa! Festa에서 당신이 찾는 이벤트를 만나보세요. festa.io Test Driven Developement란 말 그대로 테스트가 개발을 주도하는 것이다. 테스트를 먼저 만들고 그 테스트를 통과하기 위한 코드를 짜는 것을 뜻한다. 보통 개발이 끝난 후 테스트를 시행하지만 다음과 같은 장점들 때문에 그 순서를 바꾼 T.. 2020. 4. 3.
스위프트 101 - Objects and Classes Class 'class' 뒤에 class 이름을 붙여 class를 만든다. class 의 프로퍼티 선언은 상수나 변수선언과 동일하다. 하지만 프로퍼티들은 해당 classd의 context에 속해진다. 함수도 같은 방법으로 사용하면 된다. Class instance 만들기 클래스 인스턴스를 만드려면 이름 뒤에 괄호를 붙여주면 된다. 또한 class의 프로퍼티에 접근하기 위해선 쩜(.)을 사용하면 된다. var shape = Shape() shape.numberOfSides = 7 var shapeDescription = shape.simpleDescription() 위 코드는 initializer를 빼먹고 있다. initializer는 class 의 instance 가 만들어질 때 초기 설정을 해주는 역할.. 2020. 3. 26.