18 Star 133 Fork 63

编程语言算法集 / C-Sharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Permutation.cs 756 Bytes
一键复制 编辑 原始数据 按行查看 历史
Gerson Jr 提交于 2024-01-05 20:45 . Switch to file-scoped namespaces (#433)
using System.Collections.Generic;
using System.Linq;
namespace Algorithms.Strings;
public static class Permutation
{
/// <summary>
/// Returns every anagram of a given word.
/// </summary>
/// <returns>List of anagrams.</returns>
public static List<string> GetEveryUniquePermutation(string word)
{
if (word.Length < 2)
{
return new List<string>
{
word,
};
}
var result = new HashSet<string>();
for (var i = 0; i < word.Length; i++)
{
var temp = GetEveryUniquePermutation(word.Remove(i, 1));
result.UnionWith(temp.Select(subPerm => word[i] + subPerm));
}
return result.ToList();
}
}
C#
1
https://gitee.com/TheAlgorithms/C-Sharp.git
git@gitee.com:TheAlgorithms/C-Sharp.git
TheAlgorithms
C-Sharp
C-Sharp
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891