Last active
November 11, 2018 16:38
-
-
Save RQN/8af49aa34e7105fe957f to your computer and use it in GitHub Desktop.
重複順列(再帰)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using System.Collections.Generic; | |
static IEnumerable<string> Generate(string[] keyword, int length) | |
{ | |
if (length > 1) | |
{ | |
foreach (var key in keyword) | |
{ | |
foreach (var key2 in Generate(keyword, length - 1)) | |
{ | |
yield return key + key2; | |
} | |
} | |
} | |
else | |
{ | |
foreach (var key in keyword) | |
{ | |
yield return key; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment