当前位置:网站首页>1016. substring can represent binary string of numbers from 1 to n
1016. substring can represent binary string of numbers from 1 to n
2022-06-21 23:13:00 【Mr Gao】
1016. A substring can represent from 1 To N A binary string of numbers
Given a binary string s And a positive integer n, If for [1, n] Every integer in the range , Its binary representation is s Of Substring , Just go back to true, Otherwise return to false .
Substring Is a sequence of consecutive characters in a string .
Example 1:
Input :s = “0110”, n = 3
Output :true
Example 2:
Input :s = “0110”, n = 4
Output :false
int len;
char *f(int n){
len=0;
int p=n;
while(p){
len++;
p=p/2;
}
char *cs=(char *)malloc(sizeof(char)*(len+1));
int i=0;
p=n;
while(p){
// printf(" %d ",len-i-1);
cs[len-i-1]='0'+p%2;
i++;
p=p/2;
}
cs[len]='\0';
// printf("%s ",cs);
return cs;
}
bool f2(char *s, char *cs,int len){
int i;
for(i=0;i<len;i++){
if(s[i]!=cs[i]){
return false;
}
}
return true;
}
bool queryString(char * s, int n){
int i;
int j;
for(j=1;j<=n;j++){
int r=0;
char *cs=f(j);
int sl=strlen(s);
for(i=0;i<=sl-len;i++){
if(f2(cs,s+i,len)){
r=1;
break;
}
}
if(r!=1){
return false;
}
}
return true;;
}
边栏推荐
- C # error: the exception of the task is not observed by waiting for the task or accessing the exception attribute of the task. As a result, the finalizer thread re threw an unobserved exception.
- WPF startup with parameters
- 4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED
- Uniapp encapsulates the request function to achieve unique login. One account can only log in to one device at the same time
- Uwp tablet inkcanvas
- Fedora 36 compiling and installing opencv 4.6.0 -- the road to building a dream
- uniapp微信授权之 有个别用户 无法正常授权
- Postgres slice data through limit
- SIGIR2022 | 對話式推薦系統中的用戶偏好建模
- WSL 2 的安装过程(以及介绍)
猜你喜欢

Migration of stm32f407 program to stm32f429

阿里出品!图形化的ant脚本——IDEA插件CloudToolkit

Left hand code, right hand open source, part of the open source road

软件测试概念篇

numpy矩阵初等变换

Sigir2022 | modélisation des préférences des utilisateurs dans le système de recommandation dialogique

H5之微信授权登陆 (uniapp网页版微信授权登录)

解决opencv在pycharm中代码提示失效

《MATLAB 神经网络43个案例分析》:第19章 基于SVM的手写字体识别

Specific methods of using cloud development to realize wechat payment
随机推荐
Danfoss inverter maintenance vlt5000/vlt6000/vlt8000
An error prone to appear when MATLAB is doing image processing: to improve the operation speed, use the pre declared zero matrix to store image data
Some users of uniapp wechat authorization cannot be authorized normally
【强烈推荐】Markdown 语法大全
WPF listbox virtualization
Niuke month race - insectivores on the ring
Text text associated with scroll scroll bar in Tkinter
WPF startup with parameters
Sigir2022 | modélisation des préférences des utilisateurs dans le système de recommandation dialogique
C delete files in use
Multi order MFCC extraction for speech signal processing (matlab)
WPF data binding: data source target
[wustctf2020] plain and unpretentious -1
解决opencv在pycharm中代码提示失效
Left hand code, right hand open source, part of the open source road
Software testing concepts
Explain JS micro task and macro task in simple terms
STM32 cannot download the program again after downloading it once, and the program cannot run.
pointer-events的三个值的使用
Games101 job 7- detailed explanation of implementation steps of multi thread speed up