Judge Route Circle
生活随笔
收集整理的這篇文章主要介紹了
Judge Route Circle
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這道題為簡單題,網上通過率接近70%,我就不怎么仔細講了
題目:
思路:
題目太簡單,我也沒怎么多想,直接暴力解決,然后就導致時間運行太慢 = =
代碼:
1、這是我的寫的,很菜
1 class Solution(object): 2 def judgeCircle(self, moves): 3 """ 4 :type moves: str 5 :rtype: bool 6 """ 7 a = 0 8 b = 0 9 for i in moves: 10 if i == 'R': a += 1 11 if i == 'L': a -= 1 12 if i == 'U': b += 1 13 if i == 'D': b -= 1 14 if a == 0 and b == 0: return True 15 else: return False2、大神的簡潔代碼:
1 def judgeCircle(self, moves): 2 c = collections.Counter(moves) 3 return c['L'] == c['R'] and c['U'] == c['D']?
轉載于:https://www.cnblogs.com/liuxinzhi/p/7502413.html
總結
以上是生活随笔為你收集整理的Judge Route Circle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个整数,它加上100后是一个完全平方数
- 下一篇: 通过SSIS的“查找”组件进行不同数据源