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;
    }
}
相关推荐
Nil2086 小时前
leetcode 118杨辉三角
算法·leetcode·职场和发展
wanderist.8 小时前
线性筛法详解:从筛质数到欧拉函数、Möbius 函数与约数函数
java·数据结构·算法
All for pursuit.9 小时前
【设计-1】208.实现Trie (前缀树)
数据结构·c++·算法·leetcode
weixin_307779139 小时前
C++代码实现MATLAB中的crossval函数功能
开发语言·c++·算法·matlab
青少儿编程课堂9 小时前
背包问题(0/1 背包与完全背包)解题精讲——动态规划入门
c++·python·算法·bfs·信息学竞赛
光影少年9 小时前
为什么 JavaScript 中 0.1 + 0.2 !== 0.3,如何让其相等?
前端·javascript·算法
HEJOO910 小时前
Linux 设备驱动系列——使用全局工作队列
java·linux·算法
Code_Solitude10 小时前
c语言:递归
java·c语言·算法
edtoplort11 小时前
OpenAI紧急叫停GPT-6.1 Astra训练,奥尔特曼为何踩刹车
人工智能·gpt·算法
蒜香可达鸭11 小时前
让视频生成流水线跑不崩:一个事件溯源的多 Agent 可靠执行框架
算法