657. 机器人能否返回原点

657. 机器人能否返回原点


Java代码:

java 复制代码
class Solution {
    public boolean judgeCircle(String moves) {
        int[] x = {0, 0, -1, 1};
        int[] y = {1, -1, 0, 0};
        String str = "UDLR";

        int xx = 0, yy = 0;
        for (int i = 0; i < moves.length(); i++) {
            xx += x[str.indexOf(moves.charAt(i))];
            yy += y[str.indexOf(moves.charAt(i))];
        }

        return xx == 0 && yy == 0;
    }
}
相关推荐
foundbug99917 分钟前
自适应滤除直达波干扰的MATLAB实现
开发语言·算法·matlab
CN-Dust2 小时前
【C++】while语句例题专题
数据结构·c++·算法
灵智实验室2 小时前
PX4位置速度估计技术详解(四):LPE 激光雷达高度融合的实现错误
算法·无人机·px 4
CQU_JIAKE2 小时前
【A】3742,3387,并查集
算法
gihigo19982 小时前
CHAN时延估计算法(二维/三维定位实现)
算法
freexyn3 小时前
Matlab自学笔记七十六:表达式的展开、因式分解、化简、合并同类项
笔记·算法·matlab
样例过了就是过了3 小时前
LeetCode热题 不同路径
c++·算法·leetcode·动态规划
dog2503 小时前
圆锥曲线和二次曲线
开发语言·网络·人工智能·算法·php
Wadli3 小时前
27.单调队列
算法
Navigator_Z4 小时前
LeetCode //C - 1031. Maximum Sum of Two Non-Overlapping Subarrays
c语言·算法·leetcode