leetcode 777. Swap Adjacent in LR String | 777. 在LR字符串中交换相邻字符(双指针)
生活随笔
收集整理的這篇文章主要介紹了
leetcode 777. Swap Adjacent in LR String | 777. 在LR字符串中交换相邻字符(双指针)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目
https://leetcode.com/problems/swap-adjacent-in-lr-string/
題解
本來(lái)以為是個(gè)帶 visited 集合的 DFS,一看數(shù)據(jù)量,居然是 10^4。
然后看了下 hint,Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX.,一想,有點(diǎn)像狀態(tài)機(jī)嘛。
詳見(jiàn)草稿:
總結(jié)
以上是生活随笔為你收集整理的leetcode 777. Swap Adjacent in LR String | 777. 在LR字符串中交换相邻字符(双指针)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: leetcode 775. Global
- 下一篇: leetcode 1217. Minim