Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '6.9.8'
s.version = '6.9.8.1'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
8 changes: 1 addition & 7 deletions lib/easy/1417_reformat_the_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def reformat(s)
letters = []
digits = []
s.each_char do |c|
if _1417_is_letter?(c)
if c =~ /[A-Za-z]/
letters << c
else
digits << c
Expand Down Expand Up @@ -37,9 +37,3 @@ def reformat(s)

''
end

# @param {String} s
# @return {Boolean}
def _1417_is_letter?(s)
s =~ /[A-Za-z]/
end
10 changes: 1 addition & 9 deletions lib/easy/1796_second_largest_digit_in_a_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def second_highest(s)
max = -1
result = -1
s.each_char do |c|
next unless _1796_is_digit?(c)
next unless c =~ /\d/

num = c.to_i
if num > max
Expand All @@ -20,11 +20,3 @@ def second_highest(s)

result
end

# @param {String} s
# @return {Boolean}
def _1796_is_digit?(s)
code = s.ord

code >= 48 && code <= 57
end
12 changes: 2 additions & 10 deletions lib/easy/1805_number_of_different_integers_in_a_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def num_different_integers(word)
while p < word.length
c = word[p]

unless _1805_is_digit?(c)
unless c =~ /\d/
p += 1

next
end

leading_zero = c == '0'
num = []
while _1805_is_digit?(c)
while c =~ /\d/
if !leading_zero
num << c
elsif c != '0'
Expand All @@ -38,11 +38,3 @@ def num_different_integers(word)

uniq.length
end

# @param {String} s
# @return {Boolean}
def _1805_is_digit?(s)
code = s.ord

code >= 48 && code <= 57
end
10 changes: 1 addition & 9 deletions lib/easy/2042_check_if_numbers_are_ascending_in_a_sentence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def are_numbers_ascending(s)
prev = -1
s.split.each do |word|
next unless _2043_is_digit?(word[0])
next unless word[0] =~ /\d/

num = word.to_i

Expand All @@ -17,11 +17,3 @@ def are_numbers_ascending(s)

true
end

# @param {String} s
# @return {Boolean}
def _2043_is_digit?(s)
code = s.ord

code >= 48 && code <= 57
end
8 changes: 1 addition & 7 deletions lib/easy/819_most_common_word.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def most_common_word(paragraph, banned)
counter = 0
words_with_count = {}
paragraph.downcase.each_char do |c|
if _819_is_letter?(c)
if c =~ /[A-Za-z]/
word << c
else
candidate = word.join.strip
Expand All @@ -30,9 +30,3 @@ def most_common_word(paragraph, banned)

most_common_word || word.join
end

# @param {String} s
# @return {Boolean}
def _819_is_letter?(s)
s =~ /[A-Za-z]/
end
10 changes: 2 additions & 8 deletions lib/easy/917_reverse_only_letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def reverse_only_letters(s)
r = chars.length - 1
while l < r
l_c = chars[l]
unless _917_is_letter?(l_c)
unless l_c =~ /[A-Za-z]/
l += 1

next
end

r_c = chars[r]
unless _917_is_letter?(r_c)
unless r_c =~ /[A-Za-z]/
r -= 1

next
Expand All @@ -31,9 +31,3 @@ def reverse_only_letters(s)

chars.join
end

# @param {String} s
# @return {Boolean}
def _917_is_letter?(s)
s =~ /[A-Za-z]/
end
Loading