给你一个字符串 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. 重新排列字符串的更多相关文章

  1. Leetcode(8)字符串转换整数

    Leetcode(8)字符串转换整数 [题目表述]: 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当我 ...

  2. [leetcode]6. ZigZag Conversion字符串Z形排列

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  3. LeetCode刷题总结-字符串篇

    本文梳理对LeetCode上有关字符串习题的知识点,并给出对应的刷题建议.本文建议刷题的总数为32题.具体知识点如下图: 1.回文问题 题号:5. 最长回文子串,难度中等 题号:214. 最短回文串, ...

  4. [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 ...

  5. [LeetCode] Decode String 解码字符串

    Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...

  6. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  7. [LeetCode] Scramble String 爬行字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  8. Leetcode 125 Valid Palindrome 字符串处理

    题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...

  9. [LeetCode] Magical String 神奇字符串

    A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magic ...

随机推荐

  1. Vulnhub系列:Os-hackNos

    0x01环境搭建 靶机链接: https://www.vulnhub.com/entry/hacknos-os-hacknos,401/发布日期: 2019.11.27靶机描述: 描述 难度:容易中级 ...

  2. 开发 IDEA Plugin 引入探针,基于字节码插桩获取执行SQL

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 片面了! 一月三舟,托尔斯泰说:"多么伟大的作家,也不过就是在书写自己的片 ...

  3. PayPal支付-Reaact框架

    前情提要 之前用React框架做过一个网站的开发,客户是国外的公司,所以为迎合受众,支付模块添加了我国不常用但国外常用的Paypal.最近在整理文档,就把当时写的这篇经验总结再整合以下发布. payp ...

  4. Prometheus-operator 介绍和配置解析

    随着云原生概念盛行,对于容器.服务.节点以及集群的监控变得越来越重要.Prometheus 作为 Kubernetes 监控的事实标准,有着强大的功能和良好的生态.但是它不支持分布式,不支持数据导入. ...

  5. golang中的并发安全和锁

    1. 并发安全 package main import ( "fmt" "sync" ) var ( sum int wg sync.WaitGroup ) f ...

  6. Android 12(S) 图形显示系统 - SurfaceFlinger的启动和消息队列处理机制(四)

    1 前言 SurfaceFlinger作为Android图形显示系统处理逻辑的核心单元,我们有必要去了解其是如何启动,初始化及进行消息处理的.这篇文章我们就来简单分析SurfaceFlinger这个B ...

  7. linux主机名称文件修改

    目录 一:linux主机名称查看与修改 1.查看自己主机名: 3.临时修改 4.永久修改 一:linux主机名称查看与修改 1.查看自己主机名: [root@localhost ~]# echo $H ...

  8. Python的开发环境

    Python的开发环境 在 Python 开发环境中我们能看到很多工具,如 pip .conda .poetry . virtualenv . venv . pyenv 等等.他们是什么,都有什么作用 ...

  9. Learning local feature descriptors with triplets and shallow convolutional neural networks 论文阅读笔记

    题目翻译:学习 local feature descriptors 使用 triplets 还有浅的卷积神经网络.读罢此文,只觉收获满满,同时另外印象最深的也是一个浅(文章中会提及)字. 1 Cont ...

  10. ApacheCN 深度学习译文集 20201229 更新

    新增了七个教程: TensorFlow 和 Keras 应用开发入门 零.前言 一.神经网络和深度学习简介 二.模型架构 三.模型评估和优化 四.产品化 TensorFlow 图像深度学习实用指南 零 ...