日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LeetCode 答案(Easy)(601-700)

發(fā)布時(shí)間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode 答案(Easy)(601-700) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

657-Judge Route Circle (判斷 圈形路線)

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
一開始,機(jī)器人位于(0,0)。輸入一串移動(dòng)次序命令,判斷機(jī)器人是否走了一個(gè)圈,也就是說它是否回到了原點(diǎn)。

The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R (Right), L (Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.
移動(dòng)順序是一串字符串。每一步移動(dòng)命令都是一個(gè)字符。有效的移動(dòng)命令包括 R(向右) ,L(向左),U(向上)以及D(向下)。最終的輸出是true或者false,同來表示機(jī)器人是否走了一個(gè)圈。

Example 1: Input: "UD" Output: true Example 2: Input: "LL" Output: false
  • 答案
public class Solution {public boolean judgeCircle(String moves) {// x軸坐標(biāo)int x = 0;// y軸坐標(biāo)int y = 0;for (int j = 0, length = moves.length(); j < length; j++) {if (moves.charAt(j) == 'R') {x++;}if (moves.charAt(j) == 'L') {x--;}if (moves.charAt(j) == 'U') {y++;}if (moves.charAt(j) == 'D') {y--;}}// System.out.println("機(jī)器人當(dāng)前的坐標(biāo)是:("+x+","+y+")");return (x==0&&y==0);} }

總結(jié)

以上是生活随笔為你收集整理的LeetCode 答案(Easy)(601-700)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。