// 演算法 / Algorithm:
// 1) 用 minmax 找出範圍兩端。 / Find range endpoints with min/max.
// 2) 用 vector<bool> seen 標記出現過的值（值域 1..100）。 / Mark presence in a boolean vector.
// 3) 從 min 到 max 收集未出現的值，順序遍歷所以結果已排序。 / Collect in order → already sorted.

class Solution {
public:
    vector<int> findMissing(vector<int>& nums) {
        // vector<bool> 是一個布林陣列；大小 101 可容納索引 0..100。
        // vector<bool> is a boolean array; size 101 covers indices 0..100.
        vector<bool> seen(101, false);

        // *min_element / *max_element 回傳範圍內最小/最大值的「值」。
        // *min_element / *max_element return the smallest/largest VALUE in the range.
        // begin()/end() 是 vector 的頭尾迭代器。/ begin()/end() are the container's iterators.
        int minVal = *min_element(nums.begin(), nums.end());
        int maxVal = *max_element(nums.begin(), nums.end());

        // range-for：依序取出 nums 裡的每個值 v，逐一標記存在。
        // range-for: iterate each value v in nums and mark it present.
        for (int v : nums) {
            seen[v] = true;  // 標記 v 出現過 / flag v as seen
        }

        vector<int> result;  // 動態陣列，會自動擴充 / dynamic array that grows as needed

        // 從 min 掃到 max（含兩端），收集沒被標記的值。
        // Sweep [min, max] inclusive; collect values not marked.
        for (int v = minVal; v <= maxVal; v++) {
            if (!seen[v]) {              // !seen[v] 代表 v 缺失 / not seen ⇒ missing
                result.push_back(v);     // 加到結果尾端 / append to result
            }
        }

        // 因為 v 遞增遍歷，result 天生排序，直接回傳。
        // Since v increases, result is already sorted; return it directly.
        return result;
    }
};
