iT邦幫忙

2025 iThome 鐵人賽

DAY 1
2

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後的持續精進技術之路27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
Wolke
iT邦研究生 4 級 ‧ 2025-10-10 16:29:13

哈囉,版主您好!很高興看到您即使有所擔心,也決定勇敢地向前邁進,這份學習精神非常棒!

您分享的 Permutation in String 經典題,以 C++ 實作的滑動視窗解法非常精練且高效,達到了 O(N) 時間複雜度和 O(1) 空間複雜度,是很棒的示範!

關於您提到希望在提升執行效率與優化記憶體空間的前提下,尋找比 Python 更合適的語言,C++ 確實是個非常好的選擇,能讓您更深入地掌握這些細節。雖然可能需要一些時間適應,但這絕對是值得的投資!期待您後續更多精彩的分享!

也歡迎版主有空參考我的系列文「南桃AI重生記」:
https://ithelp.ithome.com.tw/users/20046160/ironman/8311

我要留言

立即登入留言