基本思路建一个helper function, 然后从1-N依次判断是否为good number, 注意判断条件为没有3,4,7 的数字,并且至少有一个2,5,6,9, 否则的话数字就一样了, 比如88, 18等.

Improve: 利用DP去判断, 时间和空间都能降为O(lgn)

Code      T: O(Nlgn)    S; O(lgn)

class Solution:
def rotatedDigits(self, N):
## Solution: T: O(Nlgn) S; O(lgn)
def helper(n):
s = str(n)
return all(d not in "" for d in s) and any(d in '' for d in s)
ans = 0
for i in range(1,N + 1):
if helper(i):
ans += 1
return ans

[LeetCode] 788. Rotated Digits_Easy tag: **Dynamic Programming的更多相关文章

  1. [LeetCode] 53. Maximum Subarray_Easy tag: Dynamic Programming

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  2. [LeetCode] 72. Edit Distance_hard tag: Dynamic Programming

    Given two words word1 and word2, find the minimum number of operations required to convert word1to w ...

  3. [LeetCode] 120. Triangle _Medium tag: Dynamic Programming

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. [LeetCode] 276. Paint Fence_Easy tag: Dynamic Programming

    There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...

  5. [LeetCode] 256. Paint House_Easy tag: Dynamic Programming

    There are a row of n houses, each house can be painted with one of the three colors: red, blue or gr ...

  6. [LeetCode] 121. Best Time to Buy and Sell Stock_Easy tag: Dynamic Programming

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  7. [LeetCode] 152. Maximum Product Subarray_Medium tag: Dynamic Programming

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...

  8. [LeetCode] 139. Word Break_ Medium tag: Dynamic Programming

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  9. [LeetCode] 45. Jump Game II_ Hard tag: Dynamic Programming

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

随机推荐

  1. 局域网里别人如何访问我本地电脑里的nginx网站

    1.修改nginx.conf配置文件(我这里配了二级域名,所以我在二级域名配置文件修改) 把deny all全部改成autoindex on 2.关闭防火墙 3.重启nginx

  2. linux 修改hosts文件

    1.修改hostssudo gedit /etc/hosts2.添加解析记录( . )完整案例:127.0.0.1 localhost.localdomain localhost简洁记录:127.0. ...

  3. UDP协议的例子

    public class Service { // 服务器         public static void main(String[] args) {               Datagra ...

  4. 解决css设置背景透明,文字不透明

    设置元素的透明度:  -moz-opacity:0.8; /*在Firefox中设置元素透明度  filter: alpha(opacity=80); /*ie使用滤镜设置透明   但是当我们对一个标 ...

  5. windous----常用命令集合

    Windous常用命令 winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构(WMI) wupdmgr--------windows更新程 ...

  6. 使用ELK收集分析MySQL慢查询日志

    参考文档:https://www.cnblogs.com/bixiaoyu/p/9638505.html MySQL开启慢查询不详述 MySQL5.7慢查询日志格式如下 /usr/local/mysq ...

  7. 对iphone手机IMU的陀螺仪、加速度计、图像的时间戳做对齐处理

    https://blog.csdn.net/chishuideyu/article/details/77479758 加速度计和陀螺仪的时间戳一致 ros 的message filters可以做时间同 ...

  8. yum install 下载后保存rpm包

    keepcache=0 更改为1下载RPM包 不会自动删除 vi /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever ...

  9. Java进阶面试题大集合-offer不再是问题

    Java基础 1.List 和 Set 的区别 2.HashSet 是如何保证不重复的 3.HashMap 是线程安全的吗,为什么不是线程安全的(最好画图说明多线程环境下不安全)? 4.HashMap ...

  10. 深入 Vue 生命周期

    深入 Vue 生命周期 这篇博客将会从下面四个常见的应用诠释组件的生命周期,以及各个生命周期应该干什么事 1.单组件的生命周期 2.父子组件的生命周期 3.兄弟组件的生命周期 4.宏mixin的生命周 ...