Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func reverseWords(_ str: inout [Character]) {
- var i = 0
- while i < str.count {
- let last = i
- while i < str.count && str[i] != " "{
- i += 1
- }
- swap(&str, last, i - 1)
- i += 1
- }
- str.reverse()
- }
- func swap(_ str: inout [Character], _ s : Int, _ e : Int){
- var i = s
- var j = e
- while i < j {
- str.swapAt( i , j)
- i += 1
- j -= 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement