How to check if a string contains identical digits in Swift

1 Answer

0 votes
import Foundation

func isStringContainIdenticalDigits(_ s: String) -> Bool {
    return Set(s).count == 1
}

let s1 = "88888888"
print(isStringContainIdenticalDigits(s1)) 

let s2 = "999999991"
print(isStringContainIdenticalDigits(s2)) 



/*
run:

true
false

*/

 



answered Dec 31, 2024 by avibootz

Related questions

1 answer 108 views
1 answer 112 views
1 answer 127 views
1 answer 145 views
1 answer 126 views
1 answer 119 views
1 answer 131 views
...