题目地址 https://leetcode.com/problems/judge-route-circle Code 1234567891011121314151617181920 function judgeCircle(string $moves) :bool { $length = strlen($moves); $x = $y = 0; for ($i = 0; $i < $length; $i++) { if ($moves[$i] == 'U') { $y++; } elseif ($moves[$i] == 'D') { $y--; } elseif ($moves[$i] == 'R') { $x++; } elseif ($moves[$i] == 'L') { $x--; } else { continue; } } return $x == 0 && $y == 0;} 赞微海报分享
近期评论