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;
    }
}
相关推荐
We་ct14 小时前
LeetCode 137. 只出现一次的数字 II:从基础到最优的两种解法详解
前端·数据结构·算法·leetcode·typescript·位运算
CappuccinoRose14 小时前
排序算法和查找算法 - 软考备战(十五)
数据结构·python·算法·排序算法·查找算法
旖-旎14 小时前
分治(交易逆序对的总数)(6)
c++·算法·leetcode·排序算法·归并排序
北顾笙98014 小时前
day14-数据结构力扣
数据结构·算法·leetcode
Ln5x9qZC214 小时前
尾递归与Continuation
算法
一路向北he14 小时前
esp32库依赖
c语言·c++·算法
老四啊laosi14 小时前
[双指针] 6. 查找总价为目标值的两个商品
算法·力扣·总价为目标值得两商品
人间寥寥情难诉14 小时前
LRU算法本地实现
java·算法·spring
moonsea020314 小时前
2026.4.2
开发语言·c++·算法
cpp_250114 小时前
P10376 [GESP202403 六级] 游戏
c++·算法·动态规划·题解·洛谷·gesp六级