应该是常数 N的位数时间级别

我的这个方法超时很严重。。。但是特此记录 费劲巴拉写的。。。

超时:

int atMostNGivenDigitSet(char** D, int DSize, int N) {
int *array = (int *)malloc(sizeof(int) * 10);
for (int i = 0; i < 10; i ++)
array[i] = 0; for (int j = 1; j < 10; j ++) { if (j - 1 < DSize) {
char cc = D[j - 1][0];
int c = cc - 48;
array[c] = c;
}
//printf("\n%d",array[j]);
}
int totalSum = 0;
for (int i = 1; i <= N; i ++) { long sum = 0;
int num = 0;
int x = i;
int isFlag = 1;
while ( x!= 0) {
isFlag = 0;
num = x % 10; //末尾数字
sum = sum * 10;//进位
sum += num;
x = x / 10;
if (array[num] == 0) {
isFlag = 1;
break;
}
}
if (isFlag == 0) {
totalSum ++;
}
}
free(array);
return totalSum;
} int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!\n");
//[-2,-1] ---> -1 char *s[] = {"1","3","5","7"};
int maxNum = atMostNGivenDigitSet(s, 4, 100);
printf("\n%d\n",maxNum);
}
return 0;
}

LeetCode 902. Numbers At Most N Given Digit Set的更多相关文章

  1. [LeetCode] 902. Numbers At Most N Given Digit Set 最大为 N 的数字组合

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  2. 902. Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  3. [Swift]LeetCode902. 最大为 N 的数字组合 | Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  4. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  5. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  6. Leetcode: Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. [LeetCode] Consecutive Numbers 连续的数字 --数据库知识(mysql)

    1. 题目名称   Consecutive Numbers 2 .题目地址 https://leetcode.com/problems/consecutive-numbers/ 3. 题目内容 写一个 ...

  8. LeetCode902. Numbers At Most N Given Digit Set

    题目: We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  ...

  9. [LeetCode] Lexicographical Numbers 字典顺序的数字

    Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,1 ...

随机推荐

  1. JQuery------制作div模态框

    转载: http://blog.csdn.net/li_xiao_ming/article/details/6738922 如图: 代码: html(使用opacity的话content无法变为不透明 ...

  2. Struts2_day01--导入源文件_Struts2的执行过程_查看源代码

    导入源文件 选中按ctrl + shift + t进入 Struts2执行过程 画图分析过程 过滤器在服务器启动时创建,servlet在第一次访问时创建 查看源代码 public class Stru ...

  3. 第十二章:Linux中权限控制实例

    前言 前文对 Linux 中的权限进行了较为透彻的分析.而本文,则在前文的基础上,具体说明如何在代码中进行权限控制. 下面的代码涉及到以下几个方面: 1. 创建文件时设置文件权限 2. 修改文件的默认 ...

  4. Gradle 模板配置

    对于新手配置Gradle是一件很痛苦的事,记住二句话绝对搞定 1.在Gradle-->gradle-wrapper.properties中配置distributionUrl=https\://s ...

  5. 设置eclipse中python脚本的编码格式

    今天在运行python脚本时报如下错误: SyntaxError: Non-ASCII character '\xe5' in file D:\pythonlearn1\src\day01\direc ...

  6. codevs 5962 [SDOI2017]数字表格

    输入描述 Input Description  [题解] 对于蓝色部分预处理前缀积. 然后在用除法分块搞一下. O(Q*sqrt(min(n,m))*logn+nlogn) #include<c ...

  7. poj 1386

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11312   Accepted: 3862 De ...

  8. js 模拟 select 的 click 事件

    法一. 你可以直接通过修改 select 的 size 属性来实现,但是这样比较丑,很明显:原来: 修改 size: 跟原生比丑在两点: 位置上移了 滚动条出现了 法二. 比较好的实现,就是通过 js ...

  9. lofter个人网站文艺愤青下载

    lofter地址→点击访问 你妹扫我        生成地址

  10. 170410、java Socket通信的简单例子(TCP)

    服务端代码: package com.bobohe.socket; import java.io.*; import java.net.*; import java.applet.Applet; pu ...