当前位置: 首页> 文旅> 旅游 > 免费高清视频素材网_web网页开发基础_seo云优化公司_郑州网站优化平台

免费高清视频素材网_web网页开发基础_seo云优化公司_郑州网站优化平台

时间:2025/7/9 6:38:20来源:https://blog.csdn.net/ElseWhereR/article/details/146526705 浏览次数:1次
免费高清视频素材网_web网页开发基础_seo云优化公司_郑州网站优化平台

*************

C++

topic:657. 机器人能否返回原点 - 力扣(LeetCode)

*************

inspect the topic very first.

It is letters to decide which side the robot moves. And my thought is quite sample. Assumeing the robot can move back to the origin, then the numbers of L have to be the same with the numbers of R. So are U and D.

Then the code can be easy to write. Travel through the string and count the letters.

class Solution {
public:bool judgeCircle(string moves) {int n = moves.size(); // to figure out the size at firstint countR = 0;int countL = 0;int countU = 0;int countD = 0;for (int i = 0; i < n; i++){if (moves[i] == 'R'){countR = countR + 1;}else if (moves[i] == 'L'){countL = countL + 1;}else if (moves[i] == 'U'){countU = countU + 1;}else{countD++;}}if (countR == countL && countD == countU){return true;}else{return false;}}
};

However, I donot think it is a elegent code. If you gays finish the Nine-year compulsory education,you will know coordinate system.

↑ y = y + 1;

↓ y = y - 1;

← x = x - 1;

→ x = x + 1;

class Solution {
public:bool judgeCircle(string moves) {int x = 0;int y = 0;for (char c : moves) {if (c == 'U') y++;else if (c == 'D') y--;else if (c == 'R') x++;else if (c == 'L') x--;}return x == 0 && y == 0;}
};

It is do elegent.

Maybe apple would change the design of ios in the near future. I donot care whether the ios system is fluently or not, I just want to see what desigh looks.

关键字:免费高清视频素材网_web网页开发基础_seo云优化公司_郑州网站优化平台

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: