iT邦幫忙

2025 iThome 鐵人賽

DAY 1
1

https://ithelp.ithome.com.tw/upload/images/20250915/20177944Q0yFYglAmz.jpg

大家好:) 原本預計是要複習之前的內容,但又覺得應該向前邁進,雖然很擔心但還是試看看><。
主要方向為後續prepare
語言之前只有用過python,但因為想要盡量提升執行效率、但也要可以記得起來前提看是否有機會優化記憶體空間。

  1. Permutation in String
class Solution{//567 O(N) O(1)
public:
    bool checkInclusion(string s1,string s2){
        int m=s1.size(),n=s2.size(); if(m>n) return false;
        int cnt[26]={0},need=m; for(char c:s1) ++cnt[c-'a'];
        for(int r=0;r<n;++r){
            if(cnt[s2[r]-'a']-->0) --need;
            if(r>=m && cnt[s2[r-m]-'a']++>=0) ++need;
            if(!need) return true;
        } return false;
    }
};

https://ithelp.ithome.com.tw/upload/images/20250915/20177944ei73O0V3vQ.jpg

https://ithelp.ithome.com.tw/upload/images/20250915/201779444WcyuiPKQu.jpg


下一篇
Sliding Window 6->7 &教育訓練
系列文
轉職仔之Data Science and ai master後的持續精進技術之路5
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言