Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 14, 2021 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/6cbc37ea3545ea42d116f1b0082a7a74 to your computer and use it in GitHub Desktop.
Save vrat28/6cbc37ea3545ea42d116f1b0082a7a74 to your computer and use it in GitHub Desktop.
Ambiguous coordinates(Python)
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