Skip to content

Commit 226f3b8

Browse files
committed
2024-12-23 v. 7.4.4: added "678. Valid Parenthesis String"
1 parent b2e8d1a commit 226f3b8

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
608608
| 662. Maximum Width of Binary Tree | [Link](https://leetcode.com/problems/maximum-width-of-binary-tree/) | [Link](./lib/medium/662_maximum_width_of_binary_tree.rb) | [Link](./test/medium/test_662_maximum_width_of_binary_tree.rb) |
609609
| 669. Trim a Binary Search Tree | [Link](https://leetcode.com/problems/trim-a-binary-search-tree/) | [Link](./lib/medium/669_trim_a_binary_search_tree.rb) | [Link](./test/medium/test_669_trim_a_binary_search_tree.rb) |
610610
| 677. Map Sum Pairs | [Link](https://leetcode.com/problems/map-sum-pairs/) | [Link](./lib/medium/677_map_sum_pairs.rb) | [Link](./test/medium/test_677_map_sum_pairs.rb) |
611+
| 678. Valid Parenthesis String | [Link](https://leetcode.com/problems/valid-parenthesis-string/) | [Link](./lib/medium/678_valid_parenthesis_string.rb) | [Link](./test/medium/test_678_valid_parenthesis_string.rb) |

leetcode-ruby.gemspec

+1-1
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 = '7.4.3'
8+
s.version = '7.4.4'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/valid-parenthesis-string/
4+
# @param {String} s
5+
# @return {Boolean}
6+
def check_valid_string(s)
7+
l = 0
8+
h = 0
9+
s.each_char do |c|
10+
l += c == '(' ? 1 : -1
11+
h += c == ')' ? -1 : 1
12+
13+
break if h.negative?
14+
15+
l = [l, 0].max
16+
end
17+
18+
l.zero?
19+
end
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/678_valid_parenthesis_string'
5+
require 'minitest/autorun'
6+
7+
class ValidParenthesisStringTest < ::Minitest::Test
8+
def test_default_one = assert(check_valid_string('()'))
9+
10+
def test_default_two = assert(check_valid_string('(*)'))
11+
12+
def test_default_three = assert(check_valid_string('(*))'))
13+
end

0 commit comments

Comments
 (0)