Press "Enter" to skip to content

花花酱 LeetCode 788 Rotated Digits

题目大意:

给一个字符串,独立旋转每个数字180°,判断得到的新字符串是否合法。

  1. 出现数字3,4,7一定不合法
  2. 新字符串 == 原来字符串不合法

X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other; 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number.

Now given a positive number N, how many numbers X from 1 to N are good?

Note:

  • N  will be in range [1, 10000].

Solution 1: Brute Force

Time complexity: O(nlogn)

C++

Bit  Operation

 

请尊重作者的劳动成果,转载请注明出处!花花保留对文章/视频的所有权利。
如果您喜欢这篇文章/视频,欢迎您捐赠花花。
If you like my articles / videos, donations are welcome.

Buy anything from Amazon to support our website
您可以通过在亚马逊上购物(任意商品)来支持我们

Paypal
Venmo
huahualeetcode
微信打赏

Be First to Comment

Leave a Reply