From 0dccd6357cd1c8cae115fe39aa8939d98bb0c941 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Wed, 8 May 2024 08:01:02 +0100 Subject: [PATCH] Swift Implementation for LCCI 16.20 --- lcci/16.20.T9/README.md | 28 ++++++++++++++++++++++++++++ lcci/16.20.T9/README_EN.md | 28 ++++++++++++++++++++++++++++ lcci/16.20.T9/Solution.swift | 25 +++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 lcci/16.20.T9/Solution.swift diff --git a/lcci/16.20.T9/README.md b/lcci/16.20.T9/README.md index 6bb77b087ae7e..e05129dc776db 100644 --- a/lcci/16.20.T9/README.md +++ b/lcci/16.20.T9/README.md @@ -154,6 +154,34 @@ function getValidT9Words(num: string, words: string[]): string[] { } ``` +```swift +class Solution { + func getValidT9Words(_ num: String, _ words: [String]) -> [String] { + let s = "22233344455566677778889999" + var d = Array(repeating: 0, count: 26) + for i in 0..<26 { + d[i] = Int(s[s.index(s.startIndex, offsetBy: i)].asciiValue! - Character("0").asciiValue!) + } + var ans: [String] = [] + let n = num.count + for w in words { + var ok = true + for i in 0.. diff --git a/lcci/16.20.T9/README_EN.md b/lcci/16.20.T9/README_EN.md index b208ad02bb777..ae2f2fdc476f2 100644 --- a/lcci/16.20.T9/README_EN.md +++ b/lcci/16.20.T9/README_EN.md @@ -160,6 +160,34 @@ function getValidT9Words(num: string, words: string[]): string[] { } ``` +```swift +class Solution { + func getValidT9Words(_ num: String, _ words: [String]) -> [String] { + let s = "22233344455566677778889999" + var d = Array(repeating: 0, count: 26) + for i in 0..<26 { + d[i] = Int(s[s.index(s.startIndex, offsetBy: i)].asciiValue! - Character("0").asciiValue!) + } + var ans: [String] = [] + let n = num.count + for w in words { + var ok = true + for i in 0.. diff --git a/lcci/16.20.T9/Solution.swift b/lcci/16.20.T9/Solution.swift new file mode 100644 index 0000000000000..3da17d694046a --- /dev/null +++ b/lcci/16.20.T9/Solution.swift @@ -0,0 +1,25 @@ +class Solution { + func getValidT9Words(_ num: String, _ words: [String]) -> [String] { + let s = "22233344455566677778889999" + var d = Array(repeating: 0, count: 26) + for i in 0..<26 { + d[i] = Int(s[s.index(s.startIndex, offsetBy: i)].asciiValue! - Character("0").asciiValue!) + } + var ans: [String] = [] + let n = num.count + for w in words { + var ok = true + for i in 0..