Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe3b4ad

Browse files
authored
Merge pull request #227 from sir-gon/develop
[REFACTOR] sonarcloud fixes: Loops should be simplified using the "Wh...
2 parents 4249c0d + 3310520 commit fe3b4ad

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

‎src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/NewYearChaos.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ public static int minimumBribesCalculate(List<int> q)
2727

2828
List<int> fragment = q[Math.Min(Math.Max(value - 2, 0), i)..i];
2929

30-
foreach (int k in fragment)
31-
{
32-
if (k > value)
33-
{
34-
bribes += 1;
35-
}
36-
}
30+
bribes += fragment.Count(k => k > value);
31+
3732
i += 1;
3833
}
3934

‎src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@ public static bool checkMagazineCompute(List<string> magazine, List<string> note
3232
ArgumentNullException.ThrowIfNull(magazine);
3333
ArgumentNullException.ThrowIfNull(note);
3434

35-
Dictionary<string, int> dictionary = [];
36-
37-
foreach (string word in magazine)
38-
{
39-
if (!dictionary.TryAdd(word, 1))
40-
{
41-
int currentValue = dictionary[word];
42-
dictionary[word] = currentValue + 1;
43-
}
44-
}
35+
Dictionary<string, int> dictionary = magazine
36+
.GroupBy(word => word)
37+
.ToDictionary(g => g.Key, g => g.Count());
4538

4639
foreach (string word in note)
4740
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /