Skip to content

Commit a2793fd

Browse files
committed
2025-02-24 v. 8.6.9: added "1529. Minimum Suffix Flips"
1 parent 5d577cb commit a2793fd

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
702702
| 1492. The kth Factor of n | [Link](https://leetcode.com/problems/the-kth-factor-of-n/) | [Link](./lib/medium/1492_the_kth_factor_of_n.rb) | [Link](./test/medium/test_1492_the_kth_factor_of_n.rb) |
703703
| 1504. Count Submatrices With All Ones | [Link](https://leetcode.com/problems/count-submatrices-with-all-ones/) | [Link](./lib/medium/1504_count_submatrices_with_all_ones.rb) | [Link](./test/medium/test_1504_count_submatrices_with_all_ones.rb) |
704704
| 1525. Number of Good Ways to Split a String | [Link](https://leetcode.com/problems/number-of-good-ways-to-split-a-string/) | [Link](./lib/medium/1525_number_of_good_ways_to_split_a_string.rb) | [Link](./test/medium/test_1525_number_of_good_ways_to_split_a_string.rb) |
705+
| 1529. Minimum Suffix Flips | [Link](https://leetcode.com/problems/minimum-suffix-flips/) | [Link](./lib/medium/1529_minimum_suffix_flips.rb) | [Link](./test/medium/test_1529_minimum_suffix_flips.rb) |
705706
| 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) |
706707
| 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) |
707708
| 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.8'
8+
s.version = '8.6.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/minimum-suffix-flips/
4+
# @param {String} target
5+
# @return {Integer}
6+
def min_flips(target)
7+
flip = '0'
8+
result = 0
9+
10+
(0...target.size).each do |i|
11+
next if target[i] == flip
12+
13+
flip = target[i]
14+
result += 1
15+
end
16+
17+
result
18+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/1529_minimum_suffix_flips'
5+
require 'minitest/autorun'
6+
7+
class MinimumSuffixFlipsTest < ::Minitest::Test
8+
def test_default_one = assert_equal(3, min_flips('10111'))
9+
10+
def test_default_two = assert_equal(3, min_flips('101'))
11+
end

0 commit comments

Comments
 (0)