我想在JavaScript中創建一個函數,對於給定的字符串,通過每次只刪除字符串中的4個字符來輸出 所有可能的組合。我如何輸出所有的組合?起始字符串的長度是動態的。提前感謝。如何通過每次刪除4個字符來獲取字符串的所有組合?
**注:**刪除4個字符的順序不應該總是連續
例子:
string:BmamdWRtaW51dGfVzZMI= //B m a m d W R t a W 5 1 d G f V z Z M I =
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
想印刷這樣所有可能的組合:
BmamdWRtaW51dGfVzZMI= (starting string)
-dWRtaW51dGfVzZMI= (removed first 4 characters)
-BWRtaW51dGfVzZMI= (removed 4 consecutive charaters start from 2th character)
-BmRtaW51dGfVzZMI= (removed 4 consecutive charaters start from 3th character)
-BmataW51dGfVzZMI= (removed 4 consecutive charaters start from 4th character)
-
-
你有沒有嘗試過任何特殊的方法這麼遠? – Nisarg
這4個字符總是連續的嗎? –
感謝您的回覆。 @讓 - 克勞德科萊特4個角色不應該總是連續的,我想打印出所有可能的組合。 – user1788736