Love丶FFC's Blog
最初,机器人位于(0, 0)处。 给定一系列动作,判断该机器人的移动轨迹是否是一个环,这意味着它最终会回到原来的位置。
移动的顺序由字符串表示。 每个动作都由一个字符表示。 有效的机器人移动是R(右),L(左),U(上)和D(下)。 输出应该为true或false,表示机器人是否回到原点。
样例1:
输入: "UD"
输出: true
样例2:
输入: "LL"
输出: false
1.以坐标的形式来移动位置和判断位置。
2.因为只有四种走法,可以使用switch进行判断。
package LintCode_Easy; public class _1104{ public static void main(String[] args) { String moves="LL"; int xplace = 0,yplace=0; for(int i=0;i<moves.length();i++) { switch (moves.charAt(i)) { case 'U':yplace++;break; case 'D':yplace--;break; case 'L':xplace--;break; case 'R':xplace++;break; default: break; } } boolean placejudge=(xplace==0 && yplace==0)?true:false; System.out.println(placejudge); } }
public class Solution { public boolean judgeCircle(String moves) { int xplace = 0,yplace=0; for(int i=0;i<moves.length();i++) { switch (moves.charAt(i)) { case 'U':yplace++;break; case 'D':yplace--;break; case 'L':xplace--;break; case 'R':xplace++;break; default: break; } } boolean placejudge=(xplace==0 && yplace==0)?true:false; return placejudge; } }
Abupguele
LASIX and potassium help buy zithromax online canada Bella, USA 2022 06 28 08 05 03
Outlils
How Veterinarians Diagnose Heartworm Disease in Cats cialis order online 040, respectively Fig
invoimi
Adverse events were adjudicated by an independent, blinded clinical events committee safe cialis online
invoimi
We were warned that it could take several cycles of treatment to be successful buy finasteride 1mg
NBfcKdi
what would happen if a girl took a viagra pill Patients with intraductal noninvasive carcinomas were not eligible for our trial
hsvfTBms
Jamar VbmLDayJtDufVmUx 6 17 2022 levitra 20 levitra 20 mg