public class Solution {
public int NumJewelsInStones(string jewels, string stones) {
var list =
from stone in stones
where jewels.Any(jewel => stone == jewel)
select stone;
return list.Count();
}
}
Source: https://leetcode.com/problems/jewels-and-stones/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 14, 2021
Leetcode Everyday: 771. Jewels and Stones. Easy
Leetcode Everyday: 1512. Number of Good Pairs. Easy
public class Solution {
public int NumIdenticalPairs(int[] nums) {
int goodPairs = 0;
for (var i = 0; i < nums.Length - 1; ++i) {
for (var j = i + 1; j < nums.Length; ++j) {
if (nums[i] == nums[j]) {
++goodPairs;
}
}
}
return goodPairs;
}
}
Source: https://leetcode.com/problems/number-of-good-pairs/
Leetcode everyday: 1470. Shuffle the Array. Easy
public class Solution {
public int[] Shuffle(int[] nums, int n) {
var list = new List<int>();
for (var i = 0; i < n; ++i) {
list.Add(nums[i]);
list.Add(nums[n + i]);
}
return list.ToArray();
}
}
Source: https://leetcode.com/problems/shuffle-the-array/
Leetcode Everyday: 1431. Kids With Greatest Number of Candies. Easy
public class Solution {
public IList KidsWithCandies(int[] candies, int extraCandies) {
var maxCandy = candies.Max();
return candies.Select(candy => candy + extraCandies >= maxCandy).ToList();
}
}
Source:
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
Leetcode Everyday: 1672. Richest Customer Wealth. Easy
public class Solution {
public int MaximumWealth(int[][] accounts) {
return accounts.Select(a => a.Sum()).Max();
}
}
Source:
https://leetcode.com/problems/richest-customer-wealth/
Subscribe to:
Posts (Atom)