当前位置: 首页>>代码示例>>C#>>正文


C# ISet.GroupBy方法代码示例

本文整理汇总了C#中ISet.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ISet.GroupBy方法的具体用法?C# ISet.GroupBy怎么用?C# ISet.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISet的用法示例。


在下文中一共展示了ISet.GroupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WordBreak

 public IList<string> WordBreak(string s, ISet<string> wordDict) {
     var paths = new List<Tuple<int, string>>[s.Length + 1];
     paths[s.Length] = new List<Tuple<int, string>> { Tuple.Create(-1, (string)null) };
     var wordDictGroup = wordDict.GroupBy(word => word.Length);
     for (var i = s.Length - 1; i >= 0; --i)
     {
         paths[i] = new List<Tuple<int, string>>();
         foreach (var wordGroup in wordDictGroup)
         {
             var wordLength = wordGroup.Key;
             if (i + wordLength <= s.Length && paths[i + wordLength].Count > 0)
             {
                 foreach (var word in wordGroup)
                 {
                     if (s.Substring(i, wordLength) == word)
                     {
                         paths[i].Add(Tuple.Create(i + wordLength, word));
                     }
                 }
             }
         }
     }
     
     return GenerateResults(paths);
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:25,代码来源:140.WordBreakII.cs

示例2: WordBreak

 public bool WordBreak(string s, ISet<string> wordDict) {
     var f = new bool[s.Length + 1];
     f[0] = true;
     var wordDictGroup = wordDict.GroupBy(word => word.Length);
     for (var i = 1; i <= s.Length; ++i)
     {
         foreach (var wordGroup in wordDictGroup)
         {
             var wordLength = wordGroup.Key;
             if (i >= wordLength && f[i - wordLength])
             {
                 foreach (var word in wordGroup)
                 {
                     if (s.Substring(i - wordLength, wordLength) == word)
                     {
                         f[i] = true;
                         break;
                     }
                 }
             }
         }
     }
     return f[s.Length];
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:24,代码来源:139.WordBreak.cs

示例3: GroupGenericMethodsByType

        /// <summary>
        /// </summary>
        /// <param name="genericMethodSpecializations">
        /// </param>
        /// <returns>
        /// </returns>
        private static SortedDictionary<IType, IEnumerable<IMethod>> GroupGenericMethodsByType(
            ISet<IMethod> genericMethodSpecializations)
        {
            // group generic methods by Type
            var genericMethodSpecializationsGroupedByType = genericMethodSpecializations.GroupBy(g => g.DeclaringType);
            var genericMethodSpecializationsSorted = new SortedDictionary<IType, IEnumerable<IMethod>>();
            foreach (var group in genericMethodSpecializationsGroupedByType)
            {
                genericMethodSpecializationsSorted[@group.Key] = @group;
            }

            IlReader.GenericMethodSpecializations = genericMethodSpecializationsSorted;

            return genericMethodSpecializationsSorted;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:21,代码来源:Il2Converter.cs


注:本文中的ISet.GroupBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。