-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinterleaving_string_1.py
More file actions
36 lines (33 loc) · 918 Bytes
/
Copy pathinterleaving_string_1.py
File metadata and controls
36 lines (33 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# https://leetcode.com/problems/interleaving-string/
# wrong solution - fails on the follwing test case
# "aa"
# "ab"
# "abaa"
# explore both possibilities. Thinking recursive now
class Solution:
def isInterleave(self, s1, s2, s3):
"""
:type s1: str
:type s2: str
:type s3: str
:rtype: bool
"""
if len(s1) + len(s2) != len(s3):
return False
elif len(s1) == 0:
return s2 == s3
elif len(s2) == 0:
return s1 == s3
i = 0
j = 0
k = 0
while k < len(s3):
print(s3[k:], s1[i:], s2[j:])
if (i < len(s1) and s3[k] != s1[i]) and (j < len(s2) and s3[k] != s2[j]):
return False
if (i < len(s1) and s3[k] == s1[i]):
i += 1
else:
j += 1
k+=1
return True