【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- ...
随机推荐
- Postgresql Useful SQL/Commands
Update records ' and a.subscriber_id=b.subscriber_id; Connections select count(*) from pg_stat_activ ...
- STM32的指令周期
在keil中编程时,写了一行代码,然后就想知道,执行这句C代码需要多长时间. 时钟周期在这就不解释了,频率的倒数. 指令周期,个人理解就是cpu执行一条汇编指令所需要的时间. 我们知道cm3使用的三级 ...
- js中event.preventDefault()和 event.stopPropagation( ) 方法详解
event.preventDefault() 1.首先event.preventDefault()是通知浏览器不要执行与事件关联的默认动作,例如: 这里a标签的默认事件是跳转,这里我们告诉浏览器取消 ...
- Java图形界面
图形界面 JFrame在swingbao JFrame jframe = new JFrame(); iframe.setVisible(true); //设置窗口显示 jframe.setLocat ...
- 学习。NET三周心得
目前为止 学习.NET已经快一个月了,有刚开始的不懂,到中途懵懂.再到现在的简懂 ,感觉自己迷了好多天,学习程序员跟学其他的程序还不同,其他的有固定格式,而.NET则固定很少 ,一直在用方法连接前后台 ...
- list, vector, map, set 区别与用法比较
List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...
- 【概率论】5-5:负二项分布(The Negative Binomial Distribution)
title: [概率论]5-5:负二项分布(The Negative Binomial Distribution) categories: - Mathematic - Probability key ...
- 新手如何入门pytorch?
我最近的文章中,专门为想学Pytorch的新手推荐了一些学习资源,包括教程.视频.项目.论文和书籍.希望能对你有帮助:一.PyTorch学习教程.手册 (1)PyTorch英文版官方手册:https: ...
- jquery做个折叠面板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ML_Review_GMM(Ch10)
Note sth about GMM(Gaussian Mixtrue Model) 高斯混合模型的终极理解 高斯混合模型(GMM)及其EM算法的理解 这两篇博客讲得挺好,同时讲解了如何解决GMM参数 ...