iT邦幫忙

2025 iThome 鐵人賽

DAY 4
2

https://ithelp.ithome.com.tw/upload/images/20250918/20177944qYzKRdvCe4.jpg

class Solution {
public:
    int longestOnes(vector<int>& a, int k) {
        int l=0, r=0, n=(int)a.size();
        for (; r<n; ++r) {
            if (a[r]==0) --k;            // 用
            if (k<0 && a[l++]==0) ++k;   // 超標縮左;丟到0補回配額
        }
        return r - l;                     // 最終視窗即最長
    }
};![https://ithelp.ithome.com.tw/upload/images/20250918/20177944OOx7S2WnHy.jpg](https://ithelp.ithome.com.tw/upload/images/20250918/20177944OOx7S2WnHy.jpg)

上一篇
Sliding Window 7->8 &到部門囉:)
下一篇
Sliding Window 9->10 & 還有好聲音可以聽真是不可思議:O
系列文
轉職仔之Data Science and ai master後的持續精進技術之路5
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言