Skip to content
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

2023-01-25 v. 1.2.9: added "657. Robot Return to Origin" #178

Merged
merged 1 commit into from
Jul 25, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 643. Maximum Average Subarray I | [Link](https://leetcode.com/problems/maximum-average-subarray-i/) | [Link](./lib/easy/643_maximum_average_subarray_i.rb) |
| 645. Set Mismatch | [Link](https://leetcode.com/problems/set-mismatch/) | [Link](./lib/easy/645_set_mismatch.rb) |
| 653. Two Sum IV - Input is a BST | [Link](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/) | [Link](./lib/easy/653_two_sum_iv_input_is_a_bst.rb) |
| 657. Robot Return to Origin | [Link](https://leetcode.com/problems/robot-return-to-origin/) | [Link](./lib/easy/657_robot_return_to_origin.rb) |
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 = '1.2.8'
s.version = '1.2.9'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
Expand Down
23 changes: 23 additions & 0 deletions lib/easy/657_robot_return_to_origin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# https://leetcode.com/problems/robot-return-to-origin/
# @param {String} moves
# @return {Boolean}
def judge_circle(moves)
hor = 0
vert = 0
(0..moves.length).each do |i|
case moves[i]
when 'U'
vert += 1
when 'D'
vert -= 1
when 'L'
hor += 1
when 'R'
hor -= 1
end
end

hor.zero? && vert.zero?
end
16 changes: 16 additions & 0 deletions test/easy/test_657_robot_return_to_origin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/657_robot_return_to_origin'
require 'minitest/autorun'

class RobotReturnToOriginTest < ::Minitest::Test
def test_default
assert(judge_circle('UD'))
assert(!judge_circle('LL'))
end

def test_additional
assert(judge_circle('RL'))
end
end
Loading