Created
May 14, 2021 06:04
-
-
Save vrat28/6cbc37ea3545ea42d116f1b0082a7a74 to your computer and use it in GitHub Desktop.
Ambiguous coordinates(Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def ambiguousCoordinates(self, S): | |
def make(frag): | |
N = len(frag) | |
for d in xrange(1, N+1): | |
left = frag[:d] | |
right = frag[d:] | |
if ((not left.startswith('0') or left == '0') | |
and (not right.endswith('0'))): | |
yield left + ('.' if d != N else '') + right | |
S = S[1:-1] | |
return ["({}, {})".format(*cand) | |
for i in xrange(1, len(S)) | |
for cand in itertools.product(make(S[:i]), make(S[i:]))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment