题目如下:

解题思路:我的方案是先把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. Gym 100942A Three seamarks

    题目链接: http://codeforces.com/problemset/gymProblem/100942/A ----------------------------------------- ...

  2. qbzt day3 上午

    内容提要 堆 lca(最近公共祖先) st表 hash 并查集 树状数组 线段树 数据结构 1.堆 Priority_queue 他滋兹:插入删除查询最大值(最小值) 分为大根堆小根堆 2.LCA 首 ...

  3. 用Vue来实现音乐播放器(八):自动轮播图啊

    slider.vue组件的模板部分 <template> <div class="slider" ref="slider"> <d ...

  4. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_6_练习_序列化集合

  5. 跟我学OpenResty(Nginx+Lua)开发目录贴 (转)

    使用Nginx+Lua开发近一年的时间,学习和实践了一些Nginx+Lua开发的架构,为了让更多人使用Nginx+Lua架构开发,利用春节期间总结了一份基本的学习教程,希望对大家有用.也欢迎谈探讨学习 ...

  6. python接口自动化:https请求,取消警告

    实现代码如下: import requests r=requests.get('https://www.baidu.com',verify=False) rr=r.content.decode() p ...

  7. SSM003/构建Maven单模块项目(一)

    一.环境准备 1.开发工具:IDEA 2.JDK版本:jdk1.8 3.Maven版本:apache-maven-3.2.5 4.数据库mysql. 二.基于Maven构建web项目 Step1:Fi ...

  8. pandas 入门(2)

    from pandas import Series, DataFrame, Index import numpy as np from numpy import nan as NA obj = Ser ...

  9. css:设置div边框透明+渐变

    写作背景: 觅兼职--登陆页面,UI给的原型图很漂亮,其中有一个图要求div外面有一圈透明度为0.37且带有渐变的边框.效果图如下: 在写的时候遇到了一点小小的问题:无法给同一个div设置圆角的透明+ ...

  10. python中pycharm中.py文件调用一个.py文件的函数

    在相同文件夹内调用函数: file1.py def add(x,y): print('和为:%d'%(x+y)) file2.py import A A.add(1,2)