People usually think that a number that only contains 3 or 5 is a lucky number.
Now given an integer n, and you need to find the smallest lucky number that is not less than N and the number of occurrences of 3 in this lucky number is the same as the number of occurrences of 5.
Example
Example 1:
Input: n = “3500”
Output: “3535”
Explanation:
The smallest lucky number is 3533, but the number of occurrences of 3 is not equal to the number of occurrences of 5.
The second smallest lucky number is 3535, and the number of occurrences of 3 is equal to the number of occurrences of 5.
Example 2:
Input: n = “1”
Output: “35”
Notice
1 ≤ n ≤ 10^100000
我用从最小的组合33…555… 不停找下一个稍大一点的数的方式搜索,超时了。因为根据已有的digit找下一个更大的数需要进行部分的排序,导致比较慢。不知道DFS应该如何搜索啊?求思路。