当前位置:网站首页>Rearrangement string of leetcode simple question
Rearrangement string of leetcode simple question
2022-06-29 05:53:00 【·Starry Sea】
subject
Give you a string s And a Same length Array of integers for indices .
Please rearrange the string s , Among them the first i Characters need to be moved to indices[i] The position indicated .
Return the rearranged string .
Example 1:
Input :s = “codeleet”, indices = [4,5,6,7,0,2,1,3]
Output :“leetcode”
explain : As shown in the figure ,“codeleet” After rearrangement, it becomes “leetcode” .
Example 2:
Input :s = “abc”, indices = [0,1,2]
Output :“abc”
explain : After rearranging , Each character remains in its original place .
Example 3:
Input :s = “aiohn”, indices = [3,1,4,2,0]
Output :“nihao”
Example 4:
Input :s = “aaiougrt”, indices = [4,0,2,6,7,3,1,5]
Output :“arigatou”
Example 5:
Input :s = “art”, indices = [1,0,2]
Output :“rat”
Tips :
s.length == indices.length == n
1 <= n <= 100
s Contains only lowercase English letters .
0 <= indices[i] < n
indices All values of are unique ( in other words ,indices Is an integer 0 To n - 1 A set of arrangements formed ).
source : Power button (LeetCode)
Their thinking
take indices and s Corresponding element bundle in , Then on indices After sorting , Output s that will do .
class Solution:
def restoreString(self, s: str, indices: List[int]) -> str:
d={
}
for i,j in zip(indices,s):
d[i]=j
return ''.join([d[i] for i in range(len(s))])

边栏推荐
- Summary of redis basic knowledge points
- Quickly write MVVM code using source generators
- Conditional test, if and case conditional test statements of shell script
- The win11 file resource manager has an explicit Caton, and Microsoft promises to improve the performance in 2022
- Would like to ask, which is the better choice for securities companies? I don't understand. Is it safe to open an account online now?
- [high concurrency] deeply analyze the callable interface
- Use VS to create a static link library Lib and use
- Openfpga wishes you a happy Lantern Festival!
- 2022 recommended tire industry research report industry development prospect market analysis white paper
- Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers
猜你喜欢

Analysis report on the investment market of the development planning prospect of the recommended rare earth industry research industry in 2022 (the attachment is a link to the online disk, and the rep

Open a new ecological posture | use WordPress remote attachment to store to Cos

Annual inventory review of Alibaba cloud's observable practices in 2021

The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers

What is MES? What does it do?

Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction

Slot

Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)

There are two ways for golang to develop mobile applications

The fresh student who was born in Ali after 2000: it's really fragrant to mend this
随机推荐
Would like to ask, which is the better choice for securities companies? I don't understand. Is it safe to open an account online now?
Analysis report on the investment market of the development planning prospect of the recommended rare earth industry research industry in 2022 (the attachment is a link to the online disk, and the rep
證券開戶安全麼,有沒有什麼危險呢
Redis notes (II) operating commands for keys in redis
2022 recommended tire industry research report industry development prospect market analysis white paper
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
Cloud native annual technology inventory is released! Ride the wind and waves at the right time
2,5-di (3,4-dicarboxyphenoxy) - 4 '- phenylethynylbiphenyldianhydride (pephqda) / Qiyue custom supply porphyrin modified amphiphilic block copolymer peg113-pcl46-porphyrin
Jenkins operation Chapter 6 mail server sending build results
Analysis of ArrayList set in teacher Yang's class
The translation of those exquisite lines in the eighth season of the big bang
Top ten Devops best practices worthy of attention in 2022
Openfpga wishes you a happy Lantern Festival!
Servlet version conflict causes page 404
Why Houdini made the pyside2 plug-in crash
Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is
[high concurrency] deeply analyze the callable interface
[C language series] - branch and loop statements
ES6 Modularization: export /import
2022-01 Microsoft vulnerability notification