iT邦幫忙

2025 iThome 鐵人賽

DAY 16
1

https://ithelp.ithome.com.tw/upload/images/20250930/20177944yWxqFUJk1e.jpg

https://ithelp.ithome.com.tw/upload/images/20250930/20177944mn2EHRuDb7.jpg

https://ithelp.ithome.com.tw/upload/images/20250930/20177944zJ7XLKcUUw.jpg

https://ithelp.ithome.com.tw/upload/images/20250930/20177944TDrkkfioog.jpg

class Solution { // linter update 438 O(N) O(1)
public:
    vector<int> findAnagrams(string s, string p) {
        int n = s.size();
        int m = p.size();
        if (m > n) return {};

        int cnt[26] = {}; 
        int need = m; 
        for (char c : p) ++cnt[c - 'a'];

        vector<int> ans;
        for (int r = 0; r < n; ++r) {
            if (cnt[s[r] - 'a']-- > 0) --need;
            if (r >= m && cnt[s[r - m] - 'a']++ >= 0) ++need;
            if (!need) ans.push_back(r - m + 1);
        }
        return ans;
    }
};

感謝好心人們的幫助
https://google.github.io/styleguide/cppguide.html

https://www.weforum.org/impact/advanced-tecnologies-manufacturing-factories-scaling-innovations/


上一篇
I have memorized it 438 && 倒數五天發錢錢XD 久違了整理一下羽球拍的袋子
下一篇
Review Sliding Window 8(904) & 留學經驗分享交流中的一些思考
系列文
轉職仔之Data Science and ai master後的持續精進技術之路17
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
AndyAWD
iT邦新手 2 級 ‧ 2025-09-30 22:41:14

IT 玩很大,好酷

XD 還沒打開前只有看到IT就挑選了 對轉職仔來說也是種肯定(?

我要留言

立即登入留言