A Ruby Solution


  • 0
    I
    def judge_circle(moves)
      i = 0
      j = 0
    
      moves.split(//).each do |m|
        if m == "R"
          i += 1
        elsif m == "L"
          i -= 1
        elsif m == "U"
          j += 1
        elsif m == "D"
          j -= 1
        end
      end
    
      if i == 0 and j == 0
        true
      else
        false
      end
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.