Swift, turn String into Array(Character)


  • 0
    X

    like most C++ code, just write in Swift;

    class Solution {
        func detectCapitalUse(_ word: String) -> Bool {
            let zVal = Character("Z") 
            var chars = Array(word.characters)
            let upper = chars.filter({ $0 <= zVal }).count
            return (upper==0) || (upper==chars.count) || ((upper==1) && (chars[0] <= zVal))
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.