leetcode657(java) Judge Route Circle

4人阅读 评论(0) 收藏 举报
分类:
public boolean judgeCircle(String moves) {
        boolean result = false;
        char l='L';
        char r='R';
        char u='U';
        char d='D';
        int unumber=0;
        int dnumber=0;
        int lnumber=0;
        int rnumber=0;
        char[] a = moves.toCharArray();
        for(int i=0;i<a.length;i++){
            if(u==a[i]){
                unumber++;
            }
            if(d==a[i]){
                dnumber++;
            }
            if(r==a[i]){
                rnumber++;
            }
            if(l==a[i]){
                lnumber++;
            }
        }
        if(lnumber==rnumber&&unumber==dnumber){
            return true;
        }
        return result;
    }

用switch case 的话方便点

查看评论

【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
  • 1097

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
  • 506

LeetCode——657.Judge Route Circle

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

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
  • 577

leetcode657: Judge Route Circle

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m...
  • sinat_35425429
  • sinat_35425429
  • 2017-08-20 20:03:46
  • 53

leetcode657——Judge Route Circle

题目大意:问一个机器人按照所指示的方向(一个字符串)走完之后会不会回到原点。UDLR分别代表上下左右。分析:字符串应用代码:class Solution {public: int dir[4][2] ...
  • tzyshiwolaogongya
  • tzyshiwolaogongya
  • 2018-03-15 21:02:54
  • 10

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
  • 1108

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
    个人资料
    等级:
    访问量: 256
    积分: 116
    排名: 122万+
    文章分类
    文章存档
    最新评论