알게 된 것
String.components(separatedBy: String)
로 문자열 자르기(기준이 되는 것은 사라짐)- components 는 반환형이 [String]
- 비슷한
String.split(seperator: Charcter)
는 반환형이 [Substring]이며 조금 더 빠르다고 한다.
- Dictionary의 사용
- 딕셔너리 생성
var dict: [String: Int] = [:]
- 딕셔너리 값 추가, 수정
let aa = dict["a", default: 1]
알게 된 것
let setArray = Set(Array)
로 배열을 한번에 Set형태로 변환하기Array(repeating: 0, count: id_list.count)
로 동일한 크기의 배열 초기화하기
알게 된 것
- m/n의 올림처리 -> (m + n - 1)/n
- Dictionary의 sort
let sortedTimeDict = timeDict.sorted(by: < )
알게 된 것
- k진법으로 변환 -> String(n, radix: k)
- 추가적으로 filter를 통해서 ""에 대한 처리가 가능함(원래는 optional 처리로 했음)
- sqrt(Double(n))로 제곱근을 구할 수 있음
- 간만에 소수를 구하는 방법을 복습
알게 된 것
- 이진 탐색의 기본 원리(왜 1부터 무작정 체크하지 않고 중간을 찾아가야 하는지 - 너무 큰 수이기 때문에)
알게 된 것
- 그래프의 기본적인 복습
- queue를 활용한 bfs 적용
-
func bfs(_ f: Int, _ depth: Int) { let edges: [Int] = connect[f] // f에서 갈 수 있는 리스트 for edge in edges { if visited[edge] == false { queue.append(edge) visited[edge] = true result[edge] = depth+1 } } }
- 시간 초과 이슈
-
let maxV = result.max() return result.filter { $0 == maxV}.count // result.filter { $0 == result.max()}.count로 했더니 틀림(할때마다 max를 계산하게 한다)
알게 된 것
- 플루이드 와샬 알고리즘 복습
-
for k in 1...n { // 거쳐가는 곳 for i in 1...n { // 시작 for j in 1...n { // 끝 if board[i][j] > board[i][k] + board[k][j] { board[i][j] = board[i][k] + board[k][j] } } } }