This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func solution(_ n:Int64) -> Int64 { | |
| func isSquareRootInt(_ number: Int64) -> Bool { | |
| let squareRoot = sqrt(Double(n)) | |
| return squareRoot == floor(squareRoot) | |
| } | |
| if isSquareRootInt(n) { | |
| return Int64((sqrt(Double(n))+1)*(sqrt(Double(n))+1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func solution(_ n:Int64) -> Int | |
| { | |
| var array:[Int] = [] | |
| var result = "" | |
| for number in String(n) | |
| { | |
| array.insert(Int(String(number)) ?? 0, at: 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func solution(_ n:Int64) -> [Int] | |
| { | |
| var answer:[Int] = [] | |
| for number in String(n) | |
| { | |
| answer.insert(Int(String(number)) ?? 0, at: 0) | |
| } | |
| return answer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func solution(_ n:Int) -> Int | |
| { | |
| var answer:Int = 0 | |
| var input = n | |
| while input > 0 { | |
| answer += input%10 | |
| input /= 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func solution(_ s:String) -> String { | |
| var uppercaseToggle = true | |
| return String(s.map { (character) -> Character in | |
| if uppercaseToggle && character != " " { | |
| uppercaseToggle = false | |
| return Character(character.uppercased()) | |
| } | |
| uppercaseToggle = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func solution(_ n:Int) -> Int { | |
| var sum = 0 | |
| if n == 1 || n == 0 { | |
| return n | |
| } | |
| for quotient in 1...n/2 { | |
| if n%quotient == 0 { | |
| sum += quotient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func solution(_ s:String, _ n:Int) -> String { | |
| let smallLetters: [Character] = Array("abcdefghijklmnopqrstuvwxyz") | |
| let largeLetters: [Character] = Array("abcdefghijklmnopqrstuvwxyz".uppercased()) | |
| var result = [Character]() | |
| for character in Array(s) { | |
| if smallLetters.contains(character) { | |
| let smallIndex: Int = smallLetters.firstIndex(of: character)! | |
| let resultIndex = smallIndex+n >= 26 ? smallIndex+n-26 : smallIndex+n | |
| result.append(smallLetters[resultIndex]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func solution(_ s:String) -> Int { | |
| return Int(s) ?? 0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct Stack<Element> { | |
| private var storage: [Element] = [] | |
| public init(_ elements: [Element]) { | |
| storage = elements | |
| } | |
| } | |
| extension Stack: CustomStringConvertible { | |
| public var description: String { | |
| """ | |
| ----top---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func isBalance(input: String) -> Bool { | |
| var stack = Stack<String>() | |
| for character in input { | |
| if character == "(" { | |
| stack.push("(") | |
| } | |
| if character == ")" { | |
| stack.pop() | |
| } | |
| } |