当前位置:网站首页>Leetcode: push domino (domino simulation)
Leetcode: push domino (domino simulation)
2022-06-24 22:36:00 【Review of the white speed Dragon King】

Ideas :
Find both sides left and right, The leftmost can be set to L, The rightmost is set to R, No effect
If in the same direction , Then the middle is reversed in the same direction
If reverse and cohesive , In the middle
Then continue the double pointer traversal left and right that will do
src
class Solution:
def pushDominoes(self, dominoes: str) -> str:
# I little interesting
n = len(dominoes)
s = list(dominoes)
# On the left is 'L' No effect
left = 'L'
right = '.'
i = 0
while i < n:
j = i
# A continuous segment has not been pushed
while j < n and s[j] == '.':
j += 1
# Find the one on the right , On the far right R No effect
right = s[j] if j < n else 'R'
# If the two directions are the same , Then the middle domino goes in the same direction
if left == right:
while i < j:
s[i] = right
i += 1
# If the directions are opposite
elif left == 'R' and right == 'L':
k = j - 1
while i < k:
s[i] = 'R'
s[k] = 'L'
i += 1
k -= 1
left = right
i = j + 1
return ''.join(s)
summary :
Double pointer simulation , Introduction of default directions on both sides
边栏推荐
- Future development of education industry of e-commerce Express
- Data communication foundation - Ethernet port mirroring and link aggregation
- Problèmes de concurrence dans l'allocation de mémoire en tas
- The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
- Main steps of system test
- 干货丨产品的可行性分析要从哪几个方面入手?
- CDN principle
- Zero code can apply data visualization to enterprise management
- Row and column differences in matrix construction of DX HLSL and GL glsl
- Genesis public chain and a group of encryption investors in the United States gathered in consensus 2022
猜你喜欢

Idea close global search box

Seven principles of software design

2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)

Docker installs redis-5.0.12. Detailed steps

L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验

Genesis公链与美国一众加密投资者齐聚Consensus 2022

无心剑汉英双语诗003. 《书海》

The logic of "Ali health" has long changed

Idea global search replace shortcut key

YGG 近期游戏合作伙伴一览
随机推荐
Raspberry pie preliminary use
[ingénierie logicielle] points clés à la fin de la période
Kubevela v1.2 release: the graphical operation console velaux you want is finally here
中国SSD行业企业势力全景图
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
Huada 04A operating mode / low power consumption mode
L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
华大4A0GPIO设置
How does flutter use the online transcoding tool to convert JSON to model
Docker installs MySQL 8.0. Detailed steps
Certificate photo processing
磁盘的结构
Servlet详解
What aspects should we start with in the feasibility analysis of dry goods?
1. fully explain the basic principles of IPSec
envoy获取客户端真实IP
网上立案流程
Why can some programmers get good offers with average ability?
进程的通信方式
04A中断的配置