Scribbling

[C++] lower_bound 본문

Computer Science/C++

[C++] lower_bound

focalpoint 2024. 2. 6. 00:17

https://leetcode.com/problems/longest-increasing-subsequence/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution {
public:
    int lengthOfLIS(vector<int>& nums) {
        vector<int> tmp;
        for (int num : nums) {
            auto it = lower_bound(tmp.begin(), tmp.end(), num);
            if (it == tmp.end()) {
                tmp.push_back(num);
            } else {
                *it = num;
            }
        }
        return tmp.size();
    }
};