- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRegexQuestionMark.py
More file actions
Latest commit
31 lines (26 loc) · 605 Bytes
/
Copy pathRegexQuestionMark.py
File metadata and controls
31 lines (26 loc) · 605 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
'''
Given a string consist of '1','0' and '?'
return all the matching strings,
“?” can match 0 or 1
For example:
input : 1??
output: {100, 101, 110, 111}.
input: 100100?00?
output: {1001000000,1001000001,1001001000,1001001001}
'''
defMatching(listStr,level):
iflevel==len(listStr):
printlistStr
return
iflistStr[level] =='?':
listStr[level] ='0'
Matching(listStr,level+1)
listStr[level] ='1'
Matching(listStr,level+1)
listStr[level] ='?'
else:
Matching(listStr,level+1)
defMain(string):
result=list(string)
Matching(result,0)
Main('1??')