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
class Solution { | |
func intToRoman(_ num: Int) -> String { | |
// if statement is faseter than switch statement (-8ms) | |
switch num { | |
case 0 : | |
return "" | |
case 1000... : | |
return "M" + intToRoman(num - 1000) | |
case 900... : |
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
class Solution { | |
func romanToInt(_ s: String) -> Int { | |
guard s.count > 0 else { | |
return 0 | |
} | |
let arr = Array(s) | |
var resInt: Int = 0 | |
var tempVal: Character = " " |
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
class Solution { | |
func myAtoi(_ str: String) -> Int { | |
guard str.count > 0 else { | |
return 0 | |
} | |
var trimmedStr = str.trimmingCharacters(in: .whitespaces) | |
guard trimmedStr.count > 0 else { |
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
class Solution { | |
func isPalindrome(_ x: Int) -> Bool { | |
if x < 0 { | |
return false | |
} | |
let arr = String(x) | |
let revArr = String(x).reversed() | |
if arr == String(revArr) { |
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
class Solution { | |
func convert(_ s: String, _ numRows: Int) -> String { | |
var groups = [[String]](repeating: Array(repeating: " ", count: s.count), count: numRows) | |
var idx = 0 | |
var v = 0 | |
var h = 0 | |
var str = "" | |
var resStr = "" | |
if numRows == 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
class Solution { | |
func reverse(_ x: Int) -> Int { | |
let str: String = String(x) | |
let arr = str.reversed().filter{( $0 != ".")} | |
var result: Int | |
var resStr: String = "" | |
if x == -0 { | |
return 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
class Solution { | |
func longestPalindrome(_ s: String) -> String { | |
// x 문자와 같은 문자가 나올때까지 for문, tempStr값에 계속 추가 | |
// x와 같은 문자가 나왔을시 그 문자를 tempStr값에 포함한 후 tempStr.count가 짝수인지, 홀수인지 확인. | |
// tempStr.count가 result.count보다 크면 진행, 아니면 continue | |
// 짝수일경우, tempStr를 절반으로 나누고 절반을 역방향으로 수정해준다. 그 후 양쪽의 데이터가 같은지 확인하고, 같으면 result에 추가. | |
// 홀수일경우, tempStr의 중간 인덱스를 제외한 나머지 절반을 역방향으로 수정한다. 그 후 양쪽의 데이터가 같은지 확인하고, 같으면 result에 추가. | |
if s.count < 1 || s.count > 1000 { | |
return "" | |
} |
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
class Solution { | |
func lengthOfLongestSubstring(_ s: String) -> Int { | |
guard s != "" else { | |
return 0 | |
} | |
let arr = Array(s) | |
var resStr: String = "\(arr[0])" | |
var tempStr: String = "\(arr[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
class Solution { | |
func twoSum(_ nums: [Int], _ target: Int) -> [Int] { | |
var arrRes: [Int] = [] | |
var res: Int = 0 | |
for i in 0..<nums.count-1 { | |
for j in i+1..<nums.count { | |
if (nums[i] + nums[j]) == target { | |
arrRes.append(i) |
NewerOlder