diff --git a/lib/leetcode.rb b/lib/leetcode.rb index 1f5a455..f435d68 100644 --- a/lib/leetcode.rb +++ b/lib/leetcode.rb @@ -7,6 +7,7 @@ require 'leetcode/reverse_nodes_in_k_group' require 'leetcode/median_of_two_sorted_arrays' require 'leetcode/regular_expression_matching' +require 'leetcode/number_after_double_reversal' require 'leetcode/substring_with_concat_of_all_words' require 'leetcode/count_number_of_distinct_integers_after_reverse_operations' diff --git a/lib/leetcode/number_after_double_reversal.rb b/lib/leetcode/number_after_double_reversal.rb new file mode 100644 index 0000000..63a8868 --- /dev/null +++ b/lib/leetcode/number_after_double_reversal.rb @@ -0,0 +1,7 @@ +module Leetcode + class NumberAfterDoubleReversal + def execute(num) + num.to_s.reverse.to_i.to_s.reverse.to_i == num + end + end +end \ No newline at end of file diff --git a/spec/leetcode/number_after_double_reversal_spec.rb b/spec/leetcode/number_after_double_reversal_spec.rb new file mode 100644 index 0000000..6dbf1fb --- /dev/null +++ b/spec/leetcode/number_after_double_reversal_spec.rb @@ -0,0 +1,30 @@ +RSpec.describe Leetcode::NumberAfterDoubleReversal do + describe '#execute' do + let(:num) { nil } + subject { Leetcode::NumberAfterDoubleReversal.new.execute(num) } + + context '526' do + let(:num) { 526 } + + it do + expect(subject).to be true + end + end + + context '1800' do + let(:num) { 1800 } + + it do + expect(subject).to be false + end + end + + context '0' do + let(:num) { 0 } + + it do + expect(subject).to be true + end + end + end +end \ No newline at end of file