Skip to content

Commit 6022ed6

Browse files
authored
2025-02-17 v. 8.5.9: added "1433. Check If a String Can Break Another String"
2 parents c0fb531 + c7cf2c4 commit 6022ed6

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
692692
| 1395. Count Number of Teams | [Link](https://leetcode.com/problems/count-number-of-teams/) | [Link](./lib/medium/1395_count_number_of_teams.rb) | [Link](./test/medium/test_1395_count_number_of_teams.rb) |
693693
| 1396. Design Underground System | [Link](https://leetcode.com/problems/design-underground-system/) | [Link](./lib/medium/1396_design_underground_system.rb) | [Link](./test/medium/test_1396_design_underground_system.rb) |
694694
| 1400. Construct K Palindrome Strings | [Link](https://leetcode.com/problems/construct-k-palindrome-strings/) | [Link](./lib/medium/1400_construct_k_palindrome_strings.rb) | [Link](./test/medium/test_1400_construct_k_palindrome_strings.rb) |
695+
| 1433. Check If a String Can Break Another String | [Link](https://leetcode.com/problems/check-if-a-string-can-break-another-string/) | [Link](./lib/medium/1433_check_if_a_string_can_break_another_string.rb) | [Link](./test/medium/test_1433_check_if_a_string_can_break_another_string.rb) |
695696
| 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) |
696697
| 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) |
697698
| 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.5.8'
8+
s.version = '8.5.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/check-if-a-string-can-break-another-string/
4+
# @param {String} s1
5+
# @param {String} s2
6+
# @return {Boolean}
7+
def check_if_can_break(s1, s2)
8+
c1 = s1.chars.to_a.sort
9+
c2 = s2.chars.to_a.sort
10+
11+
is_asc = true
12+
is_desc = true
13+
14+
(0...c1.size).each do |i|
15+
f = c1[i]
16+
s = c2[i]
17+
18+
if f < s
19+
is_desc = false
20+
elsif f > s
21+
is_asc = false
22+
end
23+
end
24+
25+
is_asc || is_desc
26+
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/1433_check_if_a_string_can_break_another_string'
5+
require 'minitest/autorun'
6+
7+
class CheckIfAStringCanBreakAnotherStringTest < ::Minitest::Test
8+
def test_default_one = assert(check_if_can_break('abc', 'xya'))
9+
10+
def test_default_two = assert(!check_if_can_break('abe', 'acd'))
11+
12+
def test_default_three = assert(check_if_can_break('leetcodee', 'interview'))
13+
end

0 commit comments

Comments
 (0)