<style> html, body, .ui-content { background: #222222; color: #00BFFF; } /* 設定 code 模板 */ .markdown-body code, .markdown-body tt { background-color: #ffffff36; } .markdown-body .highlight pre, .markdown-body pre { color: #ddd; background-color: #00000036; } .hljs-tag { color: #ddd; } .token.operator { background-color: transparent; } /* 設定連結 */ a, .open-files-container li.selected a { color: #89FFF8; } a:hover, .open-files-container li.selected a:hover { color: #89FFF890; } </style> ###### tags: `Leetcode` # 6304. Maximum Number of Integers to Choose From a Range I ###### Link : https://leetcode.com/contest/biweekly-contest-97/problems/maximum-number-of-integers-to-choose-from-a-range-i/ ## 題目 找到最多可以放入多少總和不超過maxSum且不存在在banned陣列中的數字 ## 程式碼 ```cpp= class Solution { public: int maxCount(vector<int>& banned, int n, int maxSum) { set<int> ban(banned.begin(), banned.end()); int result = 0, count = 0; for(int i = 1;i <= n;i++){ if(!ban.count(i)){ result += i; count++; } if(result > maxSum) return count - 1; } return count; } }; ``` ## Date ### 2023/2/4