欢迎光临散文网 会员登陆 & 注册

LeetCode 1016. Binary String With Substrings Representing 1 To N

2023-05-11 07:53 作者:您是打尖儿还是住店呢  | 我要投稿

Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.

A substring is a contiguous sequence of characters within a string.

 

Example 1:

Input: s = "0110", n = 3

Output: true

Example 2:

Input: s = "0110", n = 4

Output: false

 

Constraints:

  • 1 <= s.length <= 1000

  • s[i] is either '0' or '1'.

  • 1 <= n <= 109

使用自带函数Integer.toBinaryString()就可以的,遍历确认接,下面是代码:

Runtime: 0 ms, faster than 100.00% of Java online submissions for Binary String With Substrings Representing 1 To N.

Memory Usage: 40.4 MB, less than 72.27% of Java online submissions for Binary String With Substrings Representing 1 To N.


LeetCode 1016. Binary String With Substrings Representing 1 To N的评论 (共 条)

分享到微博请遵守国家法律