leetCode(Using C)——657. Judge Route Circle
Description:
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.
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.
Example 1:
Input: "UD"
Output: true
Example 2:
Input: "LL"
Output: false
Link:
If you want to solve the problem, you can visite the web site.click me
Code:
bool judgeCircle(char* moves) {
int i,x,y;
x=0;
y=0;
for(i=0;moves[i]!='\0';i++){
switch(moves[i]){
case 'R': x++;break;
case 'L': x--;break;
case 'U': y++;break;
case 'D': y--;break;
}
}
return x==y&&x==0?true:false;
}
Comment:
此題很簡單,但是就是題意不是很好理解,特別對於我們這種,英語半吊子的人來說,理解有點困難。
開始我以為,題目的意思是,一旦機器人回到走過的路徑,就判定走了一個circle。後來提交發現並不是,然後我又以為是回到起點才叫circle,後來測試又出錯。
最後才明白,原來要求,當所有指令執行完以後,機器人是否回到原點,如果是才叫circle,不是就不叫circle。
有木有感覺很坑。^_^
相關文章
- C. Black Circles
- leetCode(Using C)——461. Hamming DistanceLeetCode
- leetCode(Using C)——760. Find Anagram MappingsLeetCodeAPP
- leetCode(Using C)——718. Maximum Length of Repeated SubarrayLeetCode
- jquery judge element existjQuery
- Online Judge——1000.A+B Problem(c++)C++
- Leetcode Implement Queue using StacksLeetCode
- Using MongoDB in C#MongoDBC#
- LeetCode-Implement Stack Using QueuesLeetCode
- LeetCode-Implement Queue using StacksLeetCode
- cvHoughCircle 解析
- OpenCV(cv::circle())OpenCV
- LeetCode | 232 Implement Queue Using StacksLeetCode
- ZOJ 3806 Incircle and Circumcircle(幾何+二分)
- C#中using的使用C#
- angular routeAngular
- Oracle 12c: Recover tables using RMANOracle
- vue-routeVue
- laravel named routeLaravel
- Common class for judge IPV6 or IPV4
- Online Judge計算整數的和
- 【YLCircleImageView】圖片處理View
- SVG <circle> 繪製圓形SVG
- Aizu Online Judge Introduction to Programming I C語言實現 ITP1 Topic # 1AIC語言
- Laravel7.0 Route::get ()->name ('home') route ('home') 報錯Laravel
- 3.3.1 - Laravel - 5.6 - Route - 路由物件Route的建立過程Laravel路由物件
- 使用 Route macro 來定義 Route 的新方法Mac
- 溫故之C# using注意事項C#
- Business Object Validation Using Attributes in C#ObjectC#
- CircleCI 配置第一章: Docker映象 Image 配置 - 使用 CircleCI Convenience ImageDocker
- HDU 4669 Mutiples on a circle (DP , 統計)
- laravel8 routeLaravel
- Express Route的配置Express
- mysql route安裝MySql
- next-route
- [LeetCode] 232. 225 Implement Queue/Stack using Stacks/QueuesLeetCode
- 帶你快速搭建自己的Online Judge平臺
- 3.3 - Laravel - 5.6 - Route - 載入單個Route例項的主要流程Laravel