LeetCode--Judge Route Circle

1人阅读 评论(0) 收藏 举报
分类:

思路:

    遍历字符串,如果'U'和'D'相等且'L'和'R'相等,则为true。

class Solution {
    public boolean judgeCircle(String moves) {
        int[] moves_arr=new int[]{0,0,0,0};
        for(int i=0;i<moves.length();i++){
            if(moves.charAt(i)=='U'){
                moves_arr[0]++;
            }
            if(moves.charAt(i)=='D'){
                moves_arr[1]++;
            }
            if(moves.charAt(i)=='L'){
                moves_arr[2]++;
            }
            if(moves.charAt(i)=='R'){
                moves_arr[3]++;
            }
        }
        
        if((moves_arr[0]==moves_arr[1]) && (moves_arr[2]==moves_arr[3])){
            return true;
        }
        else{
            return false;
        }
    }
}

查看评论

【leetcode】657. Judge Route Circle

一、题目描述 Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if ...
  • xiaoquantouer
  • xiaoquantouer
  • 2017-08-15 10:16:38
  • 1095

python--leetcode657. Judge Route Circle

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m...
  • wenqiwenqi123
  • wenqiwenqi123
  • 2017-09-21 20:33:44
  • 570

Judge Route Circle问题及解法

问题描述: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this ...
  • u011809767
  • u011809767
  • 2017-08-14 08:39:20
  • 1104

LeetCode——657.Judge Route Circle

题目链接 题面:   Add to List 657. Judge Route Circle Descript...
  • David_Jett
  • David_Jett
  • 2017-08-21 19:47:09
  • 970

leetcode 657. Judge Route Circle

原题: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if thi...
  • zhaihaixu
  • zhaihaixu
  • 2017-08-14 09:33:36
  • 714

LeetCode 657. Judge Route Circle(C++版)

题目: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this rob...
  • Mary19920410
  • Mary19920410
  • 2017-08-18 12:24:18
  • 505

leetcode657. Judge Route Circle

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m...
  • u012033124
  • u012033124
  • 2017-11-30 21:17:58
  • 49

657. Judge Route Circle -- Python

657. Judge Route Circle Initially, there is a Robot at position (0, 0). Given a sequence of its mov...
  • Chris_zhangrx
  • Chris_zhangrx
  • 2018-01-17 21:00:46
  • 69

leetcode之 Judge Route Circle

题目很简单:本质上就是判断上下左右的次数是否相等 class Solution { public:     bool judgeCircle(string moves) {      ...
  • github_29989383
  • github_29989383
  • 2017-10-29 18:53:50
  • 63

Leetcode657. Judge Route Circle

一直刷水题,从未进步过。 class Solution { public: bool judgeCircle(string moves) { int x=0,y=0; ...
  • a197p
  • a197p
  • 2017-08-23 14:59:56
  • 169
    个人资料
    等级:
    访问量: 586
    积分: 125
    排名: 119万+
    文章分类
    文章存档