diff --git a/2554. Maximum Number of Integers to Choose From a Range I b/2554. Maximum Number of Integers to Choose From a Range I new file mode 100644 index 0000000..382f75d --- /dev/null +++ b/2554. Maximum Number of Integers to Choose From a Range I @@ -0,0 +1,19 @@ +class Solution { +public: + int maxCount(vector& banned, int n, int maxSum) { + unordered_map hash; + for (auto num: banned) { + hash[num] = 1; + } + int sum = 0, count = 0, i = 1; + while (i <= n) { + if (!hash[i]) { + if (sum + i > maxSum) return count; + sum += i; + count ++; + } + i++; + } + return count; + } +};