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;
    }
}
相关推荐
To_OC3 小时前
LC 438 找到所有字母异位词:暴力超时后,我靠滑动窗口一招搞定
javascript·算法·leetcode
Forever Nore6 小时前
学完C语言力扣第一题做不来正常吗
数据结构·算法
hansang_IR6 小时前
【题解】LC:倍增 / 区间并查集(Range Parallel Unionfind)
c++·算法·并查集
Tisfy8 小时前
LeetCode 3731.找出缺失的元素:哈希 / 排序
算法·leetcode·哈希算法·排序·哈希表
lucas_AI8 小时前
Q-CueGraph:你的多模态大模型会 zoom,但真的知道该看哪儿吗?
人工智能·算法
kaixin_啊啊9 小时前
test_机器学习算法学习
学习·算法·机器学习
liulilittle9 小时前
MOE路由:路由(logits: top-k/8)
c++·人工智能·算法·机器学习·llm
旖旎夜光9 小时前
LeetCode 11:盛最多水的容器(双指针问题) —— 题解
数据结构·c++·算法·leetcode·双指针
一只齐刘海的猫9 小时前
【Leetcode】乘积最大子数组
算法·leetcode·职场和发展