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;
    }
}
相关推荐
想吃火锅10051 小时前
【leetcode】56.合并区间js
算法·leetcode·职场和发展
imuliuliang1 小时前
可合并堆在多任务调度中的优势与实现技巧7
算法
学究天人1 小时前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷6)
网络·算法·数学建模·动态规划·几何学·图论·拓扑学
wabs6661 小时前
关于动态规划【力扣72.编辑距离的思考】
算法·leetcode·动态规划
用户333239768841 小时前
我做了一个 RepoMind:让 AI 写架构前,先去看看真实开源项目
算法
chh5631 小时前
C++--list
开发语言·数据结构·c++·学习·算法·list
killerbasd2 小时前
总结 7。10
人工智能·算法·机器学习
林间码客2 小时前
RAG系统评估指南:从入门到实践
人工智能·算法·机器学习
凌波粒2 小时前
LeetCode--47.全排列 II(回溯算法)
算法·leetcode·职场和发展
学究天人2 小时前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷8)
线性代数·算法·机器学习·数学建模·动态规划·图论·抽象代数