[LeetCode]1528. 重新排列字符串
给你一个字符串 s 和一个 长度相同 的整数数组 indices 。
请你重新排列字符串 s ,其中第 i 个字符需要移动到 indices[i] 指示的位置。
返回重新排列后的字符串。
示例 1:

输入:s = "codeleet", indices = [4,5,6,7,0,2,1,3]
输出:"leetcode"
解释:如图所示,"codeleet" 重新排列后变为 "leetcode" 。
示例 2:
输入:s = "abc", indices = [0,1,2]
输出:"abc"
解释:重新排列后,每个字符都还留在原来的位置上。
示例 3:
输入:s = "aiohn", indices = [3,1,4,2,0]
输出:"nihao"
示例 4:
输入:s = "aaiougrt", indices = [4,0,2,6,7,3,1,5]
输出:"arigatou"
示例 5:
输入:s = "art", indices = [1,0,2]
输出:"rat"
提示:
- s.length == indices.length == n
- 1 <= n <= 100
- s 仅包含小写英文字母。
- 0 <= indices[i] < n
- indices 的所有的值都是唯一的(也就是说,indices 是整数 0 到 n - 1 形成的一组排列)。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/shuffle-string
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
public class Solution {
public string RestoreString(string s, int[] indices) {
char[] result = new char[indices.Length];
for(int i = 0; i < indices.Length; i++){
result[indices[i]] = s[i];
}
return new String(result);
}
}
[LeetCode]1528. 重新排列字符串的更多相关文章
- Leetcode(8)字符串转换整数
Leetcode(8)字符串转换整数 [题目表述]: 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当我 ...
- [leetcode]6. ZigZag Conversion字符串Z形排列
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- LeetCode刷题总结-字符串篇
本文梳理对LeetCode上有关字符串习题的知识点,并给出对应的刷题建议.本文建议刷题的总数为32题.具体知识点如下图: 1.回文问题 题号:5. 最长回文子串,难度中等 题号:214. 最短回文串, ...
- [LeetCode] Arranging Coins 排列硬币
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- [LeetCode] Decode String 解码字符串
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...
- [LeetCode] Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- [LeetCode] Scramble String 爬行字符串
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...
- [LeetCode] Magical String 神奇字符串
A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magic ...
随机推荐
- JMM模型基础知识笔记
概述 内存模型可以理解为在特定的操作协议下,对特定的内存或者高速缓存进行读写访问的过程抽象,不同架构下的物理机拥有不一样的内存模型,Java虚拟机也有自己的内存模型,即Java内存模型(JavaMem ...
- RabbitMQ除开RPC的五种消模型----原生API
2.五种消息模型 RabbitMQ提供了6种消息模型,但是第6种其实是RPC,并不是MQ,因此不予学习.那么也就剩下5种. 但是其实3.4.5这三种都属于订阅模型,只不过进行路由的方式不同. 通过一个 ...
- Linux下Julia安装
1.找到官网,执行 wget https://julialang-s3.julialang.org/bin/linux/x64/1.4/julia-1.4.0-linux-x86_64.tar.gz ...
- Java将引入新的对象类型来解决内存利用问题
2022年Java将有什么新的特性和改进,我相信很多Java开发者都想知道.结合Java语言架构师布莱恩·格茨(Brian Goetz)最近的一些分享,胖哥给大家爆个料.老规矩,点赞走起. Valha ...
- golang中往脚本传递参数的两种用法os.Args和flag
1. os.Args package main import ( "fmt" "os" ) func main() { // 执行:./demo.exe 127 ...
- ubuntu输入正确密码重新跳到登录界面
原因一:/etc/profile或者/etc/enviroment 配置错误 (很多开发人员在配置完java环境之后容易出现这种情况) 解决办法(已验证): 1,开机后在登录界面按下shift+c ...
- MySql下载与安装(部署)
一:MySQL介绍 1.MySQL简介 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB ...
- 将项目上传至GitHub
前言: 前段时间我将自己做的2040小游戏从本地上传至了GitHub上,本篇将记录上传过程与方法 我的2048小游戏GitHub仓库链接226YZY/my2048game: 我的简易2048小游戏 ( ...
- Android Studio如何查看自己设计的数据库
首先点击左上角进入Device File Explorer 进入后 点击data-data 找到你的项目名称 进入后点击你建立的数据库 一步步按照提示进行操作,即可显示你的表
- aws 试题
/* Domain 1 Design Resilient Architectures 1. Which of the following statements regarding S3 storage ...