【Leetcode_easy】657. Robot Return to Origin
problem
题意:
solution1:
class Solution {
public:
bool judgeCircle(string moves) {
int cnt1 = , cnt2 = ;
for(auto move:moves)
{
if(move == 'L') cnt1++;
else if(move=='R') cnt1--;
else if(move=='U') cnt2++;
else if(move=='D') cnt2--;
}
if(cnt1== && cnt2==) return true;
else return false;
}
};
solution2:
class Solution {
public:
bool judgeCircle(string moves) {
unordered_map<char, int> mymap;
for(auto move:moves) mymap[move]++;
//return (mymap.count('L')==mymap.count('R') && mymap.count('U')==mymap.count('D'));
return mymap['L']==mymap['R'] && mymap['U']==mymap['D'];
}
};
参考
1. Leetcode_easy_657. Robot Return to Origin;
完
【Leetcode_easy】657. Robot Return to Origin的更多相关文章
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
- 【LeetCode】657. Robot Return to Origin 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 复数求和 counter统计次数 相似题目 参考资料 ...
- LeetCode 657. Robot Return to Origin
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its mov ...
- 657. Robot Return to Origin
Description There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequenc ...
- LeetCode 657 Robot Return to Origin 解题报告
题目要求 There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of it ...
- LeetCode 657. Robot Return to Origin (C++)
题目: There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its ...
- LeetCode #657. Robot Return to Origin 机器人能否返回原点
https://leetcode-cn.com/problems/robot-return-to-origin/ 设置 flagUD 记录机器人相对于原点在纵向上的最终位置 flagRL 记录机器人相 ...
- LeetCode--Squares of a Sorted Array && Robot Return to Origin (Easy)
977. Squares of a Sorted Array (Easy)# Given an array of integers A sorted in non-decreasing order, ...
- 【LeetCode】657. Judge Route Circle 解题报告
[LeetCode]657. Judge Route Circle 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/judge-route- ...
随机推荐
- easyUI--入门实例
ui框架 1.需要导入的所有jar包,以及外部的类或文件 1.1导入jar包 1.2导入WebContent外部资源 1.3导入所有需要的辅助类--Util包 2.实例代码 2.1创建TreeNode ...
- P3588 [POI2015]PUS
好题 思路:线段树优化建图+拓扑DP or 差分约束(都差不多): 提交:3次 错因:眼瞎没看题,Inf写的0x3f3f3f3f 题解: 类似差分约束的模型,\(a<b\rightarrow a ...
- 关于ORA-12154: TNS:could not resolve the connect identifier specified的问题
问题:net configuration assistant测试连接可以连接.但是PLSQL连接不了,报ORA-12154: TNS:could not resolve the connect ide ...
- 搭建自己的博客(二十二):通过ajax提交评论信息,并增加公式编辑功能
编辑功能使用到了ckeditor的MathJax组件.ajax提交评论可以不用刷新浏览器. 1.变化的部分
- 二分算法题目训练(三)——Anton and Making Potions详解
codeforces734C——Anton and Making Potions详解 Anton and Making Potions 题目描述(google翻译) 安东正在玩一个非常有趣的电脑游戏, ...
- Ubuntu16.04 安装 CUDA9.2(总结一些新手容易遇到的问题)
系统:Ubuntu16.04 64bit 显卡:Nvidia GEFORCE 940MX 驱动:NVIDIA-Linux-x86_64-396.18.run 软件:cuda_9.2.88_396.26 ...
- Selenium操作Chrome模拟手机浏览器
目录 使用指定设备 使用自定义设备 在使用Chrome浏览网页时,我们可以使用Chrome开发者工具模拟手机浏览器,在使用Selenium操作Chrome时同样也可以模拟手机浏览器.主要有以下两种用途 ...
- c++ 珊格迷宫问题
#demo1 #include<iostream> #include<ctime> #include<cstdlib> #include<queue> ...
- select选中
比如<select class="selector"></select> 1.设置value为“全部“的项选中 复制代码代码如下: $(&quo ...
- ES6---修饰器
类的修饰 许多面向对象的语言都有修饰器(Decorator)函数,用来修改类的行为.目前,有一个提案将这项功能,引入了 ECMAScript. @testable class MyTestableCl ...