当前位置:网站首页>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))])

边栏推荐
- [high concurrency] deeply analyze the callable interface
- HTTP Caching Protocol practice
- 5000+ word interpretation | Product Manager: how to do a good job in component selection?
- JIRA basic usage sharing
- Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
- Servlet version conflict causes page 404
- What is MES? What does it do?
- 机器人强化学习——第一人称 VS 第三人称
- Research Report on recommended specialized, special and new industries in 2022 industry development prospect and market investment analysis (the attachment is a link to the online disk, and the report
- 2022 recommended quantum industry research industry development planning prospect investment market analysis report (the attachment is a link to the online disk, and the report is continuously updated
猜你喜欢

What has urbanization brought to our mental health and behavior?

Modularization and modular specification commonjs

Research Report on the new energy industry of recommended power equipment in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report

Tcapulusdb Jun · industry news collection (III)

It turns out that the joys and sorrows of programmers are not interlinked

Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email

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

Why can't the article be posted?

Plugin

Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
随机推荐
VLAN experiment
C语言用 printf 打印 《爱心》《火星撞地球》等,不断更新
Quickly write MVVM code using source generators
Problems with MySQL database query
Servlet version conflict causes page 404
Leetcode theme [array] -219- duplicate Element II exists
Est - ce que l'ouverture d'un compte de titres est sécurisée? Y a - t - il un danger?
證券開戶安全麼,有沒有什麼危險呢
SCM engineering experience - time slice
Call the computer calculator and use it to convert several base numbers
[IOT] description of renaming the official account "Jianyi commerce" to "product renweipeng"
STI, one controller
Modularization and modular specification commonjs
Pytest (7) -yield and termination function
Love that can't be met -- what is the intimate relationship maintained by video chat
Structure training camp module II operation
Skills of writing test cases efficiently
How to hand over complex legacy systems?
Top ten Devops best practices worthy of attention in 2022
RTOS embarqués