public class ParkingSystem {
Dictionary<int, int> _parkSlots = new Dictionary<int, int>();
public ParkingSystem(int big, int medium, int small) {
_parkSlots[1] = big;
_parkSlots[2] = medium;
_parkSlots[3] = small;
}
public bool AddCar(int carType) {
if (_parkSlots[carType] > 0) {
--_parkSlots[carType];
return true;
}
return false;
}
}
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 14, 2021
Leetcode Everyday: 1603. Design Parking System. Easy
Leetcode Everyday: 771. Jewels and Stones. Easy
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/
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/
Subscribe to:
Posts (Atom)