GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #1016 - Binary String With Substrings Representing 1 To N - LeetCode JavaScript Solutions

Back to all solutions

#1016 - Binary String With Substrings Representing 1 To N

Medium • View on LeetCode • View on GitHub
String

Problem Description

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.

Solution

/**
 * @param {string} s
 * @param {number} n
 * @return {boolean}
 */
var queryString = function(binaryString, maxNumber) {
  return hasAllSubstrings(binaryString, maxNumber);

  function hasAllSubstrings(str, num) {
    for (let i = 1; i <= num; i++) {
      if (!str.includes(i.toString(2))) return false;
    }
    return true;
  }
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.