题目如下:

解题思路:我的方案是先把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. Ajax的封装。

    封装 Ajax 因为Ajax 使用起来比较麻烦,主要就是参数问题,比如到底使用GET 还是POST:到 底是使用同步还是异步等等,我们需要封装一个Ajax 函数,来方便我们调用.    封装支持接收来 ...

  2. vue 父子component生命周期

    如今前端框架都流行组件化,页面元素都可以使用组件进行高度概括,那么处理组件之间的关系就如同处理页面架构一样重要.正确理解组件之间的关系,才能让代码按照我们与预料方式工作.最近参与了一个Vue.js的项 ...

  3. Mac018--VisualBox & ubuntu 安装

    一.安装虚拟机VMware 参考博客:https://blog.csdn.net/u013142781/article/details/50529030 Step1:下载ubuntu镜像 注:选择Ub ...

  4. jQ判断checked是否选中

    (1).JQ1.6版本之前(不包括1.6版本)判断checkbox是否被选中用的是attr()方法,HTML代码与上面相同,只放JQ代码: console.log($("input[type ...

  5. 设置HTML中字体的粗细

    设置font-weight 属性:normal : 默认值.正常的字体.相当于 400 .声明此值将取消之前任何设置bold : 粗体.相当于 700 .也相当于 b 对象的作用bolder : 比 ...

  6. 2019春第十二周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 这里 我在这个课程的目标是 能按自己的想法解出题目 这个作业在那个具体方面帮助我实现目标 能朝着软件工程师方向发展 参考文献与网址 C语言 ...

  7. tomcat 端口8080占用问题

    启动tomcat时,有时会出现8080端口占用的问题. 解决方法: 终端:ps -e | grep tomcat 会看到下边的结果 途中标记的是进程号,kill掉即可. kill -9 9734(97 ...

  8. Pycharm 修改项目名称后 中括号中出现先前名称怎么解决?

    这时候,你打开工程的路径,会找到一个隐藏文件, .idea  目录删掉他,重新导入Pycharm 就行了. idea记录了一些工程项目信息. 步骤: 1.退出当前工程 2.打开工程路径删除.ideal ...

  9. 通过document.domain实现跨域访问

    通过document.domain实现跨域访问:https://blog.csdn.net/nlznlz/article/details/79506655 前端跨域方法之document.domain ...

  10. [2019CCPC网络赛][hdu6704]K-th occurrence(后缀数组&&主席树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6704 题意为查询子串s[l...r]第k次出现的位置. 写完博客后5分钟的更新 写完博客才发现这份代码 ...