题目如下:

解题思路:我的方案是先把S拆分成整数对,例如S='1230',先拆分成(1,230),(12,30),(123,0),然后再对前面整数对进行加小数点处理。比如(12,30)中的12可以加上小数点可以变成(12)和(1.2),(30)可以变成(30)和(3.0)。接下来对加上小数点后的结果进行配对,可以得到(12,30),(12,3.0),(1.2,30),(1.2,3.0)四种,再过滤掉不合规则的(x,3.0),就可以得到结果。

代码如下:

class Solution(object):
def is_number(self,s):
import re
if re.match('00\.',s):
return False
if re.match('^0{2,}[1-9]*\.?[0-9]*$',s):
return False
if re.match('^0+\.0*$',s):
return False
if re.match('^0+[1-9]+\.*[0-9]*$',s):
return False
if re.match('^[0-9]+\.[0-9]*0$',s):
return False
if re.match('^0[0-9]+\.?[0-9]*$',s):
return False
return True
def ambiguousCoordinates(self, S):
"""
:type S: str
:rtype: List[str]
"""
res = []
S = S.replace('(','').replace(')','')
queue = []
for i in xrange(0,len(S)-1):
queue.append((S[:i+1],S[i+1:]))
while len(queue) > 0:
x,y = queue.pop(0) xl = [x]
yl = [y]
for i in xrange(1,len(x)):
xl.append(x[:i] + '.' + x[i:])
for i in xrange(1,len(y)):
yl.append(y[:i] + '.' + y[i:]) for i in xl:
for j in yl:
if self.is_number(i) and self.is_number(j):
res.append('(' + str(i) + ', ' + str(j) + ')')
return res

【leetcode】816. Ambiguous Coordinates的更多相关文章

  1. 【LeetCode】816. Ambiguous Coordinates 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/ambiguous ...

  2. 【LeetCode】593. Valid Square 解题报告(Python)

    [LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...

  3. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  4. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  5. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  7. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  8. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  9. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

随机推荐

  1. TypeError: list indices must be integers or slices, not str

    错误如下: TypeError: list indices must be integers or slices, not str 错误代码块: aa是一组list套dict数据 函数insert接收 ...

  2. JS手写状态管理的实现(转)

    https://juejin.im/post/5c528411e51d456898361e43

  3. 《图解设计模式》读书笔记7-2 Mediator模式

    目录 Mediator模式简介 示例程序 示例程序类图 代码 Mediator模式角色和类图 角色 模式类图 思路拓展 简单化 角色复用 Mediator模式简介 Mediator模式即中介者模式,可 ...

  4. spring包

    下载的spring包中文件及各种包众多,在项目中往往只有部分是我们必须的,如果不清楚什么时候需要什么包的话,看看下面就知道了. aspectj目录 下是在Spring框架下使用aspectj的源代码和 ...

  5. Java基础/利用fastjson反序列化json为对象和对象数组

    利用fastjson反序列化json为对象和对象数组 利用 fastjosn 将 .json文件 反序列化为 java.class 和 java.util.List fastjson 是一个性能很好的 ...

  6. 东软、天健、金仕达、杭创、中联、NECHIS、军字一号 HIS产品的比较

    HIS主流厂商产品介绍1.沈阳东软医疗系统有限公司创立于1998年公司是中国目前最大的软件集团——东软集团为技术和资源依托,以研制生产大型医疗设备为主,同时为医院数字化提供全面解决方案.但是,公司改制 ...

  7. oracle--权限的传递

    sys 用户 普通授权lisi grant alter any table to lisi; 将权限指定admin ,可以权限传递给其他用户 grant alter any table to lisi ...

  8. levelDB SSTable-静态布局结构

    SSTable是Bigtable中至关重要的一块,对于LevelDB来说也是如此,对LevelDB的SSTable实现细节的了解也有助于了解Bigtable中一些实现细节.     本节内容主要讲述S ...

  9. python学习第四十五天__name__用法和作用

    在python导入模块导入另外一个模块的时候,有时候只是想用其一个方法,会出现其他的方法也运行了,python用到__name__==‘__main__’ 解决问题,那么__name__用法和作用 1 ...

  10. B.Petr and a Combination Lock

    https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...