File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Premium Question
3+ """
4+ __author__ = 'Daniel'
5+
6+
7+ class Solution (object ):
8+ def validWordAbbreviation (self , word , abbr ):
9+ """
10+ pointers
11+ :type word: str
12+ :type abbr: str
13+ :rtype: bool
14+ """
15+ w = 0
16+ a = 0
17+ while w < len (word ) and a < len (abbr ):
18+ if abbr [a ].isdigit () and abbr [a ] != '0' :
19+ e = a
20+ while e < len (abbr ) and abbr [e ].isdigit (): e += 1
21+ num = int (abbr [a :e ])
22+ a = e
23+ w += num
24+ else :
25+ if word [w ] != abbr [a ]:
26+ return False
27+
28+ w += 1
29+ a += 1
30+
31+ return w == len (word ) and a == len (abbr )
32+
33+
34+ if __name__ == "__main__" :
35+ assert Solution ().validWordAbbreviation ("internationalization" , "i12iz4n" ) == True
36+ assert Solution ().validWordAbbreviation ("apple" , "a2e" ) == False
You can’t perform that action at this time.
0 commit comments