力扣题:字符的统计-12.4
- 创业
- 2025-07-21 19:17:06

力扣题-12.4
[力扣刷题攻略] Re:从零开始的力扣刷题生活
力扣题1:657. 机器人能否返回原点解题思想:进行统计即可
class Solution(object): def judgeCircle(self, moves): """ :type moves: str :rtype: bool """ dic = {'U': 0, 'D': 0, 'R': 0, 'L': 0} for move in moves: if move == 'U': dic['U'] += 1 elif move == 'D': dic['D'] += 1 elif move == 'R': dic['R'] += 1 elif move == 'L': dic['L'] += 1 return dic['U'] == dic['D'] and dic['R'] == dic['L'] class Solution { public: bool judgeCircle(string moves) { std::unordered_map<char, int> counts{{'U', 0}, {'D', 0}, {'R', 0}, {'L', 0}}; for (char move : moves) { if (move == 'U') { counts['U']++; } else if (move == 'D') { counts['D']++; } else if (move == 'R') { counts['R']++; } else if (move == 'L') { counts['L']++; } } return counts['U'] == counts['D'] && counts['R'] == counts['L']; } };力扣题:字符的统计-12.4由讯客互联创业栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“力扣题:字符的统计-12.4”
下一篇
前端笔记(四)Flex布局