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;
    }
}
相关推荐
xyy12333 分钟前
C# Polly 弹性策略库指南
算法
geovindu1 小时前
go: Recursion Algorithm
开发语言·后端·算法·golang·递归算法
Shadow(⊙o⊙)2 小时前
日志与线程池
linux·c++·算法
冷小鱼2 小时前
AI Agent 的核心算法:多智能体协作(Multi-Agent Systems)
前端·人工智能·算法·multi-agent·多智能体协作·systems
QN1幻化引擎2 小时前
# DalinX V8 灵鉴 V2:12维意识评测框架 —— 从 Tononi IIT 到 Friston FEP 的理论统一
数据库·人工智能·算法·机器学习·数据挖掘·agi
牧以南歌〆2 小时前
数据结构<一>顺序表
c语言·数据结构·算法
Fairy要carry3 小时前
面试-训练显存占用估计
算法
触底反弹3 小时前
💥 暴力解 LeetCode 导致 OOM:10000 行数据撑爆 V8 堆内存的完整排查
javascript·算法·面试
cheems95273 小时前
[算法手记]二叉树中序,层序遍历,统计树高
算法