From 83ae6df459e6a1917a922ca1fc9faefc48cc5a68 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Tue, 8 Oct 2024 08:06:12 +0100 Subject: [PATCH 1/2] feat: add swift implementation to lcof2 problem: No.108 --- .../README.md" | 37 +++++++++++++++++++ .../Solution.swift" | 32 ++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 "lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/Solution.swift" diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" index 12309e85a5a3a..fdcec1d3730c5 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" @@ -204,6 +204,43 @@ func ladderLength(beginWord string, endWord string, wordList []string) int { } ``` +#### Swift + +```swift +class Solution { + func ladderLength(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> Int { + var words = Set(wordList) + var queue = [beginWord] + var ans = 1 + + while !queue.isEmpty { + for _ in 0.. diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/Solution.swift" "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/Solution.swift" new file mode 100644 index 0000000000000..3d1231ac00c9e --- /dev/null +++ "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/Solution.swift" @@ -0,0 +1,32 @@ +class Solution { + func ladderLength(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> Int { + var words = Set(wordList) + var queue = [beginWord] + var ans = 1 + + while !queue.isEmpty { + for _ in 0.. Date: Tue, 8 Oct 2024 07:10:19 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- .../README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" index fdcec1d3730c5..cfc23846b8909 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 108. \345\215\225\350\257\215\346\274\224\345\217\230/README.md" @@ -212,7 +212,7 @@ class Solution { var words = Set(wordList) var queue = [beginWord] var ans = 1 - + while !queue.isEmpty { for _ in 0..