Skip to content

Commit 42fc663

Browse files
authored
2025-02-19 v. 8.6.3: added "1461. Check If a String Contains All Binary Codes of Size K"
2 parents 2272216 + 2f8504f commit 42fc663

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
696696
| 1442. Count Triplets That Can Form Two Arrays of Equal XOR | [Link](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/) | [Link](./lib/medium/1442_count_triplets_that_can_form_two_arrays_of_equal_xor.rb) | [Link](./test/medium/test_1442_count_triplets_that_can_form_two_arrays_of_equal_xor.rb) |
697697
| 1448. Count Good Nodes in Binary Tree | [Link](https://leetcode.com/problems/count-good-nodes-in-binary-tree/) | [Link](./lib/medium/1448_count_good_nodes_in_binary_tree.rb) | [Link](./test/medium/test_1448_count_good_nodes_in_binary_tree.rb) |
698698
| 1457. Pseudo-Palindromic Paths in a Binary Tree | [Link](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | [Link](./lib/medium/1457_pseudo_palindromic_paths_in_a_binary_tree.rb) | [Link](./test/medium/test_1457_pseudo_palindromic_paths_in_a_binary_tree.rb) |
699+
| 1461. Check If a String Contains All Binary Codes of Size K | [Link](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/) | [Link](./lib/medium/1461_check_if_a_string_contains_all_binary_codes_of_size_k.rb) | [Link](./test/medium/test_1461_check_if_a_string_contains_all_binary_codes_of_size_k.rb) |
699700
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
700701
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
701702
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '8.6.2'
8+
s.version = '8.6.3'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
4+
# @param {String} s
5+
# @param {Integer} k
6+
# @return {Boolean}
7+
def has_all_codes(s, k)
8+
need = 1 << k
9+
exists = ::Set.new
10+
11+
(k..s.size).each do |i|
12+
str = s[i - k...i]
13+
14+
next if exists.include?(str)
15+
16+
exists << str
17+
need -= 1
18+
19+
return true if need.zero?
20+
end
21+
22+
false
23+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/1461_check_if_a_string_contains_all_binary_codes_of_size_k'
5+
require 'minitest/autorun'
6+
7+
class CheckIfAStringContainsAllBinaryCodesOfSizeKTest < ::Minitest::Test
8+
def test_default_one = assert(has_all_codes('00110110', 2))
9+
10+
def test_default_two = assert(has_all_codes('0110', 1))
11+
12+
def test_default_three = assert(!has_all_codes('0110', 2))
13+
end

0 commit comments

Comments
 (0)