<file_sep>//
//  test.swift
//  test
//
//  Created by TTOzzi on 2020/01/08.
//  Copyright © 2020 TTOzzi. All rights reserved.
//
@testable import Problem2
import XCTest

class test: XCTestCase {

    override func setUp() {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }

    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
    }

    func testPerformanceExample() {
        // This is an example of a performance test case.
        measure {
            // Put the code you want to measure the time of here.
        }
    }
    
    func testCase1() {
        XCTAssertTrue(reverse(123) == 321)
    }
    
    func testCase2() {
        XCTAssertTrue(reverse(-123) == -321)
    }
    
    func testCase3() {
        XCTAssertTrue(reverse(120) == 21)
    }
}
<file_sep>func solution(participant: [String], completion: [String]) -> String {
    var participant = participant
    var completion = completion
    var index = 0
    for player in participant {
        if completion.contains(player) {
            completion.remove(at: completion.firstIndex(of: player)!)
            participant.remove(at: index)
            index -= 1
        }
        index += 1
    }
    return participant[0]
}
<file_sep>func reverse(_ x: Int) -> Int {
    var number = x >= 0 ? x : -x
    var arr = [Int]()
    var ret = 0
    var digits = 1
    
    while number > 0 {
        arr.append(number % 10)
        number = number/10
    }
    arr.reverse()
    if x >= 0 {
        arr.forEach {
            ret += $0 * digits
            digits *= 10
        }
    } else {
        digits = -1
        arr.forEach {
            ret += $0 * digits
            digits *= 10
        }
    }
    
    return ret > 2147483647 || ret < -2147483648 ? 0 : ret
}
