Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func longestCommonPrefix(_ strs: [String]) -> String {
- if strs.count == 1 {
- return strs[0]
- }
- var pref: String = ""
- let word = strs.first ?? ""
- for index in word.indices {
- let c = word[index]
- for j in 1..<strs.count {
- if strs[j].count == pref.count || c != strs[j][index] {
- return pref
- }
- }
- pref.append(c)
- }
- return pref
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement