【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- ...
随机推荐
- @EnableCircuitBreaker熔断超时机制
客户端请求服务端的时候总是报超时,默认熔断机制是1S
- 密码加密与微服务鉴权JWT详细使用
[TOC] 1.1.了解微服务状态 微服务集群中的每个服务,对外提供的都是Rest风格的接口,而Rest风格的一个最重要的规范就是:服务的无状态性. 什么是无状态? 1.服务端不保存任何客户端请求者信 ...
- 是什么是FBC CBV
- FBV url - 函数 - CBV url - view
- Bootstrap 表单布局示例
<html> <head> <link href="../../dist/css/bootstrap.min.css" rel="style ...
- [NOI2019]序列(模拟费用流)
题意: 有两个长度为n的序列,要求从每个序列中选k个,并且满足至少有l个位置都被选,问总和最大是多少. \(1\leq l\leq k\leq n\leq 2*10^5\). 首先,记录当前考虑到的位 ...
- junit报错
java.lang.RuntimeException: iwap 环境还没有初始化,请先调用IWapContext.init(). at com.nantian.ofpiwap.IWapContext ...
- fasttext模型 训练THUCNews
# _*_coding:utf-8 _*_ import fasttext import jieba from sklearn import metrics import random def rea ...
- python版本下载时时,官方目录web-based与executable和embeddable 的区别
背景:安装python时不知道选择哪个版本以及他们之间的意思. 1.X86和X86-64的区别:系統是32 bit 的版本还是 64bit 的 2.web-based ,executable , em ...
- springboot开启gzip压缩
springboot 2.x开启gzip压缩 1.application.yml配置 server: compression: enabled: true min-response-size: mim ...
- [WEB安全]IIS-PUT漏洞
目录 0x00 IIS简介 0x01 Put漏洞造成原因 0x02 实验环境搭建 0x03 需要用到的工具 0x04 IIS-PUT漏洞演示实战 0x05 常见请求协议 0x06 漏洞修复建议 0x0 ...