当前位置:网站首页>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
边栏推荐
- Servlet详解
- 证件照处理
- 【软件工程】期末重点
- Creating files, recursively creating directories
- 1. fully explain the basic principles of IPSec
- Uncover the secret of station B. is it true that programmers wear women's clothes and knock code more efficiently?
- leetcode:515. Find the maximum value in each tree row [brainless BFS]
- 揭秘B站,程序员穿女装敲代码,效率更高是真的吗?
- 第二批入围企业公示!年度TOP100智能网联供应商评选
- Virtual private network foundation
猜你喜欢

零代码即可将数据可视化应用到企业管理中

How to compare two or more distributions: a summary of methods from visualization to statistical testing

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

In the era of full programming, should I give up this road?

How to extract dates from web pages?
How to solve the problem that the computer suddenly can't connect to WiFi

Selection and comparison of message oriented middleware MQ

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

NIO多路复用之Selector的使用

树莓派初步使用
随机推荐
FANUC机器人_KAREL编程入门学习(1)
理想L9,智能座舱新潮流
Redis-跳表
揭秘B站,程序员穿女装敲代码,效率更高是真的吗?
Technology inventory: past, present and future of Message Oriented Middleware
YGG 近期游戏合作伙伴一览
Power system | IEEE paper submission process
Firewall working principle and detailed conversation table
Information update on automatic control principle
img2pdf
NiO, bio, AIO
磁盤的結構
STP spanning tree protocol Foundation
关于自动控制原理资料更新
A pit in try with resources
Kubevela v1.2 release: the graphical operation console velaux you want is finally here
第二批入围企业公示!年度TOP100智能网联供应商评选
重磅!法大大上榜“专精特新”企业
Docker installs redis-5.0.12. Detailed steps
How to grab the mobile phone bag for analysis? Fiddler artifact may help you!