【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- ...
随机推荐
- Core DOM、HTML DOM、XML DOM关系
查看:https://blog.csdn.net/IamChuancey/article/details/78335443
- (C99)复合字面量
#include <stdio.h> struct argvs { char a[64]; int b; }; int pfunc(struct argvs *a) { printf(&q ...
- CF C. Vladik and fractions——构造题
题目 构造一组 $x, y, z$,使得对于给定的 $n$,满足 $\frac{1}{x} + \frac{1}{y} + \frac{1}{z} = \frac{2}{n}$. 分析: 样例二已 ...
- 定时器 间隔调用setInterval
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Vue动态创建注册component的实例代码
https://segmentfault.com/a/1190000015698278
- 063_显示本机 Linux 系统上所有开放的端口列表
#!/bin/bash#从端口列表中观测有没有没用的端口,有的话可以将该端口对应的服务关闭,防止意外的攻击可能性 ss -nutlp |awk '{print $1,$5}' | awk -F&quo ...
- tibco server keystore怎样使用多域名证书
Create a Subject Alternative Name certificate with Active Directory Certificate Services https://kno ...
- [Luogu] 封锁阳光大学
https://www.luogu.org/problemnew/show/P1330 #include <cstdio> #include <cstring> #includ ...
- FOI冬令营 Day1
目录 T1.全连(fc) 传送门 Code T2.原样输出(copy) 传送门 Code T3.不同的缩写(diff) 传送门 Code 打算把省冬的题目放上来,主要是防止自己偷懒不订正 T1. ...
- luogu_P3674 小清新人渣的本愿
传送门 Solution 莫队,用bitset来存储出现的数 如果是和或者差,直接通过左移右移就可以实现判断 对于积的询问,暴力判就行了,因数只要枚举\(\sqrt n\)个 总复杂度是\(O(n^2 ...