Problem 186 - Reverse words, code works locally but leetcode does not accept it


  • 0
    B
    def reverseWords(self, s):
            s.reverse()
            ind = 0
            for i in range(len(s)):
                if s[i] == '':
                    s[ind:i] = reversed(s[ind:i])
                    ind = i + 1
            
            s[ind:] = reversed(s[ind:])
    

    Leetcode does not accept this code, while it works perfectly when I run it normally. Any idea as to what might be the issue here ?


  • 0

    @bhanuverma How can this be correct? This condition s[i] == '' will never be true.


  • 0
    B

    Oops, my bad. It was a space not an empty string. Thank you.


Log in to reply
 

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