【Leetcode_easy】657. Robot Return to Origin
problem
题意:
solution1:
class Solution { public: bool judgeCircle(string moves) { int cnt1 = 0, cnt2 = 0; 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==0 && cnt2==0) 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;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/