【Leetcode】1528. Shuffle String
題目地址:
https://leetcode.com/problems/shuffle-string/
給定一個字串 s s s和一個陣列 a a a,要求返回一個新字串 t t t使得 t [ a [ i ] ] = s [ i ] t[a[i]]=s[i] t[a[i]]=s[i]。
程式碼如下:
public class Solution {
public String restoreString(String s, int[] indices) {
char[] str= new char[s.length()];
for (int i = 0; i < s.length(); i++) {
str[indices[i]] = s.charAt(i);
}
return new String(str);
}
}
時空複雜度 O ( l s ) O(l_s) O(ls)。
相關文章
- LeetCode-Shuffle an ArrayLeetCode
- LeetCode Shuffle an Array(打亂陣列)LeetCode陣列
- [LeetCode] Rotate StringLeetCode
- [leetcode] Scramble StringLeetCode
- Leetcode 481 Magical StringLeetCode
- Leetcode Reverse Words in a StringLeetCode
- leetcode Reverse Words in a StringLeetCode
- leetcode String to Integer (atoi)LeetCode
- Leetcode-Scramble StringLeetCode
- Leetcode - String to Integer (atoi)LeetCode
- Scramble String leetcode javaLeetCodeJava
- leetcode 344. Reverse StringLeetCode
- Leetcode 8 String to Integer (atoi)LeetCode
- 【Leetcode】767. Reorganize StringLeetCode
- LeetCode-Reverse Vowels of a StringLeetCode
- LeetCode-Decode StringLeetCode
- LeetCode-Reverse Words in a StringLeetCode
- Leetcode-Interleaving StringLeetCode
- String to Integer (atoi) leetcode javaLeetCodeJava
- Interleaving String leetcode javaLeetCodeJava
- Reverse Words in a String leetcode javaLeetCodeJava
- Leetcode 151 Reverse Words in a StringLeetCode
- LeetCode-Reverse Words in a String IILeetCode
- Spark shuffle調優Spark
- Spark Shuffle實現Spark
- spark Shuffle相關Spark
- [LeetCode] 678. Valid Parenthesis StringLeetCode
- [LeetCode] 844. Backspace String CompareLeetCode
- LeetCode 438. Find All Anagrams in a StringLeetCode
- 344. Reverse String--LeetCode RecordLeetCode
- LeetCode151:Reverse Words in a StringLeetCode
- LeetCode C++ 387. First Unique Character in a String【String/Hash Table】簡單LeetCodeC++
- LeetCode-Rearrange String k Distance ApartLeetCode
- leetcode第一刷_Interleaving StringLeetCode
- LeetCode 394. Decode String All In OneLeetCode
- Spark學習——排序ShuffleSpark排序
- Hadoop Shuffle詳解Hadoop
- python---np.shufflePython