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;
    }
}
相关推荐
不会就选b5 小时前
算法日常・每日刷题--<贪心>25
数据结构·算法
千里码aicood9 小时前
基于CART算法的图书分类系统设计与实现
数据库·算法·分类
做cv的小昊9 小时前
【World Model】π0.5:a Vision-Language-Action Model with Open-World Generalization
人工智能·算法·机器学习·大模型·多模态·vla·世界模型
لا معنى له10 小时前
World-In-World: World Models in a Closed-Loop World
算法
Discipline102912 小时前
尼泊尔河流流量:天气驱动的预测与高流量风险
人工智能·算法
XuCoder12 小时前
改一个数,右边全得重算,这题怎么扛住两万次查询
算法
小羊没烦恼!12 小时前
在Scrum中实施敏捷建模
java·开发语言·windows·算法·c#
weixin_3077791312 小时前
基于睿擎工业开发平台的预训练视觉模型轻量化适配与低代码部署优化
开发语言·算法
hold?fish:palm13 小时前
45 二叉树的右视图
开发语言·c++·算法