Skip to content

2024-04-16 v. 5.4.7: added "2299. Strong Password Checker II" #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -407,3 +407,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2283. Check if Number Has Equal Digit Count and Digit Value | [Link](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/) | [Link](./lib/easy/2283_check_if_number_has_equal_digit_count_and_digit_value.rb) |
| 2287. Rearrange Characters to Make Target String | [Link](https://leetcode.com/problems/rearrange-characters-to-make-target-string/) | [Link](./lib/easy/2287_rearrange_characters_to_make_target_string.rb) |
| 2293. Min Max Game | [Link](https://leetcode.com/problems/min-max-game/) | [Link](./lib/easy/2293_min_max_game.rb) |
| 2299. Strong Password Checker II | [Link](https://leetcode.com/problems/strong-password-checker-ii/) | [Link](./lib/easy/2299_strong_password_checker_ii.rb) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '5.4.6'
s.version = '5.4.7'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
32 changes: 32 additions & 0 deletions lib/easy/2299_strong_password_checker_ii.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

# https://leetcode.com/problems/strong-password-checker-ii/
# @param {String} password
# @return {Boolean}
def strong_password_checker_ii(password)
return false if password.length < 8

lower = 0
upper = 0
digit = 0
special = 0
last = '['

password.each_char do |letter|
return false if letter == last

last = letter

if letter.match?(/\d/)
digit += 1
elsif '!@\#$%^&*()-+'.include?(letter)
special += 1
elsif letter.match?(/[[:upper:]]/)
upper += 1
elsif letter.match?(/[[:lower:]]/)
lower += 1
end
end

lower.positive? && upper.positive? && special.positive? && digit.positive?
end
13 changes: 13 additions & 0 deletions test/easy/test_2299_strong_password_checker_ii.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2299_strong_password_checker_ii'
require 'minitest/autorun'

class StringPasswordCheckerIITest < ::Minitest::Test
def test_default
assert(strong_password_checker_ii('IloveLe3tcode!'))
assert(!strong_password_checker_ii('Me+You--IsMyDream'))
assert(!strong_password_checker_ii('1aB!'))
end
end