#Leetcode# 1016. Binary String With Substrings Representing 1 To N
https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/
Given a binary string S
(a string consisting only of '0' and '1's) and a positive integer N
, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring of S.
Example 1:
Input: S = "0110", N = 3
Output: true
Example 2:
Input: S = "0110", N = 4
Output: false
Note:
1 <= S.length <= 1000
1 <= N <= 10^9
代码:
class Solution {
public:
bool queryString(string S, int N) {
int num;
int len = S.length(); for(int i = 0; i <= N; i ++) {
string t = Binary(i);
if(S.find(t) == -1) return false;
}
return true;
}
string Binary(int x) {
string ans = "";
while(x) {
ans += x % 2 + '0';
x /= 2;
}
for(int i = 0; i < ans.size() / 2; i ++)
swap(ans[i], ans[ans.size() - i - 1]);
return ans;
}
};
#Leetcode# 1016. Binary String With Substrings Representing 1 To N的更多相关文章
- 【LeetCode】1023. Binary String With Substrings Representing 1 To N 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1023. Binary String With Substrings Representing 1 To N
题目如下: Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, r ...
- [Swift]LeetCode1016. 子串能表示从 1 到 N 数字的二进制串 | Binary String With Substrings Representing 1 To N
Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return ...
- [LeetCode] Special Binary String 特殊的二进制字符串
Special binary strings are binary strings with the following two properties: The number of 0's is eq ...
- 【LeetCode】761. Special Binary String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/special- ...
- leetcode 761. Special Binary String
761. Special Binary String 题意: 一个符合以下两个要求的二进制串: \(1.串中包含的1和0的个数是相等的.\) \(2.二进制串的所有前缀中1的个数不少于0的个数\) 被 ...
- [Swift]LeetCode761. 特殊的二进制序列 | Special Binary String
Special binary strings are binary strings with the following two properties: The number of 0's is eq ...
- 761. Special Binary String
Special binary strings are binary strings with the following two properties: The number of 0's is eq ...
- [LeetCode] Add Binary 二进制数相加
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
随机推荐
- Vue+Webpack常见问题(持续更新)
常识 1.computed计算属性,使用的属性必需在data里面声明. computed: { canLogin: function(){ //注意这里的依赖的属性必需在data里面声明 return ...
- npm方法
1. 使用npm 下载全局包 npm install 包名字 -g 安装 npm uninstall 包名字 -g 卸载 2. 安装卸载本地的包 (在哪里执行命令就把包安装在哪个目录的node_mod ...
- 安利一波:Adobe 2019全家桶 破解版
之前发过一篇Photoshop破解的文章,今天把笔记本换了个系统,发现之前那个amtlib.dll替换破解的方式不适用于最新版的Adobe 2019 CC系列了,刚好看到群里有大佬分享了一个全家桶,给 ...
- SQLite的sqlite3_prepare_v2
original SQL text---<sqlite3_prepare_v2>--->sqlite3_stmt--<sqlite3_reset>-->clear ...
- SDOI2017 R1做题笔记
SDOI2017 R1做题笔记 梦想还是要有的,万一哪天就做完了呢? 也就是说现在还没做完. 哈哈哈我竟然做完了-2019.3.29 20:30
- 深度学习框架PyTorch一书的学习-第三章-Tensor和autograd-2-autograd
参考https://github.com/chenyuntc/pytorch-book/tree/v1.0 希望大家直接到上面的网址去查看代码,下面是本人的笔记 torch.autograd就是为了方 ...
- docker-1-环境安装及例子实践
1.安装go 先新建一个Go的工作空间文件夹,文件夹路径建议放在$HOME下: userdeMacBook-Pro:~ user$ cd $HOME userdeMacBook-Pro:~ user$ ...
- Ubuntu 14.04 安装 CUDA 问题及解决
本文安装环境: - 双显卡: intel 集显 + nvidia 独显 - Ubuntu 14.04.4 - CUDA 8.0.44 1. Deb 安装包是个坑 (不要用这种方法!) 使用 Deb 安 ...
- day13----迭代器、生成器、枚举对象
一.迭代器: 定义: (从装有多个值的容器中一次取出一个值给外界) 器:迭代器是个容器,包含多个值 迭代:循环反馈,从容器中一次取出一个值 迭代器不同于索引取值,但是也可以从容器对象中从前往后逐个返回 ...
- 区分range() , np.arange() , np.linspace()
content: range() np.arange() np.linspace() 一.range(start, stop, step) 1.range() 为 python 自带函数 2.生成一个 ...