Return null for my python code


  • 0
    X
    class Solution:
    	# @return a boolean
    	def isScramble(self, s1, s2):
    	    if len(s1) != len(s2):
    	        return False
    	    if s1 == s2:
    	        return True
    		s1Sorted = ''.join(sorted(s1))
    		s2Sorted = ''.join(sorted(s2))
    		if s1Sorted != s2Sorted:
    			return False
    		l = len(s1)
    		for i in range(1, l):
    			s11 = s1[:i]
    			s12 = s1[i:]
    			s21 = s2[:i]
    			s22 = s2[i:]
    			if self.isScramble(s11, s21) and self.isScramble(s12, s22):
    				return True
    			s21 = s2[-i:]
    			s22 = s2[:-i]
    			if self.isScramble(s11, s21) and self.isScramble(s12, s22):
    				return True
    		return False
    

    The idea is pretty straightforward. Split the string into two parts and compare isScramble for these two parts separately.
    Given test case: "a" and "b".
    my code return null in leetcode.
    But actually, it works pretty well in my python compiler.


  • 0
    P

    Your code is totally fine, I tried submit it with your code and passed 3 times out of 3, ranging from 180-250 ms. It doesn't make sense to return null anyway......


Log in to reply
 

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