1. 程式人生 > 其它 >Python一行程式碼實現ADF檢驗(時間序列平穩性檢驗)(包含結果解讀)

Python一行程式碼實現ADF檢驗(時間序列平穩性檢驗)(包含結果解讀)

給你一個字串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是整數0n - 1形成的一組排列)。
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Solution1528 {

	public String restoreString(String s, int[] indices) {
		String out = "";
		String[] astr = new String[indices.length];

		for (int i = 0; i < indices.length; i++) {
			astr[indices[i]] = s.substring(i, i + 1);
		}
		for (int i = 0; i < indices.length; i++) {
			out = out + astr[i];
		}
		return out;
	}

	public static void main(String[] args) {

		Solution1528 sol = new Solution1528();

		String s = "codeleet";
		int[] indices = { 4, 5, 6, 7, 0, 2, 1, 3 };
		System.out.println(sol.restoreString(s, indices));
	}
}