Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/12/05 10:20), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1180/1548 (看更多)
2337. 推推樂 遇到機器人臉 '_' 就可以推 L向左推 R向右推 把start 推成target class Solution { public: bool canChange(string start, string target) { int l = 0, r = 0; int n = start.length(); // push L for(int i = 0; i < n; i++){ if(target[i] == 'L') l++; if(start[i] == 'R' and l > 0) return false; if(start[i] == 'L') l--; if(target[i] == 'R' and l > 0) return false; if(l < 0) return false; } // push R for(int i = n-1; i >= 0; i--){ if(target[i] == 'R') r++; if(start[i] == 'L' and r > 0) return false; if(start[i] == 'R') r--; if(target[i] == 'L' and r > 0) return false; if(r < 0) return false; } return (r == 0) and (l == 0); } }; 看大家都直接一圈check R跟 L 我是先看L能不能推成想要的 然後再看R能不能 跑兩圈>< ----- Sent from JPTT on my iPad -- 很姆的咪 姆之咪 http://i.imgur.com/5sw7QOj.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1733365230.A.5BF.html
文章代碼(AID): #1dKGtkM_ (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dKGtkM_ (Marginalman)