Home > Net >  A List <Dictionary <int, int> Dictionary merge together in the problem
A List <Dictionary <int, int> Dictionary merge together in the problem

Time:12-09

Dictionary to merge from the List, the two merged dictionary key value and the value of the sum, now provides two values maxKey, maxValue, merged with the biggest key value does not exceed maxKey, the largest value value does not exceed maxValue, should how to use the code realization,
If only one maximum value for example maxValue write up is very simple, will List sorted according to the value of the dictionary values, then the for loop iterates through it, from small to large, additive is greater than the maxValue words will be a dictionary before the merger into a new List, and then the maxValue reset, since this a start up, but there are two maximum words I have no idea, I ask you what method,

CodePudding user response:

If (dic) either ContainsKey (key))
{
Dic [key]=dic [key] + value;
} the else
{
Dic [key]=value;
}
  •  Tags:  
  • C#
  • Related