diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" index 710a738b34294..b0afc43b343c1 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/README.md" @@ -183,6 +183,36 @@ func isBipartite(graph [][]int) bool { } ``` +#### Swift + +```swift +class Solution { + private var parent: [Int] = [] + + func isBipartite(_ graph: [[Int]]) -> Bool { + let n = graph.count + parent = Array(0.. Int { + if parent[x] != x { + parent[x] = find(parent[x]) + } + return parent[x] + } +} +``` + diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/Solution.swift" "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/Solution.swift" new file mode 100644 index 0000000000000..9ebd6dd7071b7 --- /dev/null +++ "b/lcof2/\345\211\221\346\214\207 Offer II 106. \344\272\214\345\210\206\345\233\276/Solution.swift" @@ -0,0 +1,25 @@ +class Solution { + private var parent: [Int] = [] + + func isBipartite(_ graph: [[Int]]) -> Bool { + let n = graph.count + parent = Array(0.. Int { + if parent[x] != x { + parent[x] = find(parent[x]) + } + return parent[x] + } +} \ No newline at end of file