herrDeng網內搜尋

自訂搜尋
Ads
2025年3月13日 星期四
2025年3月8日 星期六
C++ Py3 Sliding window速解Leetcode 2379 Minimum Recolors to Get K Consec...
C++ Py3 Sliding window速解2379 Minimum Recolors to Get K Consecutive Black Blocks
[Py3 解含過程輸出請進]
2025年3月3日 星期一
2025年2月26日 星期三
C++ prefix sum Kadane Python一行解Leetcode 1749. Maximum Absolute Sum of An...
cpp prefix sum Kadane Python一行解Leetcode 1749. Maximum Absolute Sum of Any Subarray
[解答請進]
2025年2月19日 星期三
C++py3排列組合與binary表達解Leetcode 1415 The k th Lexicographical String of Al...
C++py3排列組合與binary表達解Leetcode 1415 The k th Lexicographical String of All Happy Strings of Length n
總共有3*2^(n-1)個happy strings要求第k個。先算(k-1)除以2^(n-1)的商q與餘數r,s[0]由q決定,s[1:n]由r決定,化r為二進位,然後簡單處理一下就得解
[Py3解請進]
2025年2月18日 星期二
C++ Py3 reverse 2pointer解Leetcode 2375 Construct Smallest Number From D...
C++ Py3 reverse 2pointer解Leetcode 2375 Construct Smallest Number From DI String
2025年2月14日 星期五
C++ OOP Prefix Product解Leetcode 1352 Product of the Last K Numbers
C++ OOP Prefix Product解Leetcode 1352 Product of the Last K Numbers
Leetcode這題1352. Product of the Last K Numbers,是很好的OOP題目,除了談談class之外,還能練習一下prefix product的概念(與prefix sum類似但要小心0)
[C++解請進]
2025年2月11日 星期二
2025年2月7日 星期五
Python C++ hashmap解Leetcode 3160 Find the Number of Distinct Colors Am...
Python C++ hashmap解Leetcode 3160 Find the Number of Distinct Colors Among the Balls
嘗試2個hashmap來解決。由於實際運行,可以說,Python dict 比 C++ unordered_map 快得多
[Py3 code請進]
2025年2月6日 星期四
排列組合Python解Leetcode 1726 Tuple with Same Product
本片展示如何理解這題排列組合實質內容,以及如何完成 1 行Python程式碼。
[Py3 code請進]
2025年2月3日 星期一
Python C++單迴圈速解Leetcode 3105 Longest Strictly Increasing or Strictly De...
Python cpp單迴圈速解Leetcode 3105 Longest Strictly Increasing or Strictly Decreasing Subarray
用單迴圈就可解,甚至也沒有用到if, switch, tenary
[Py3解請進]
2025年1月31日 星期五
C++ UnionFind解難題Leetcdoe 827 Making A Large Island(含Py3解)
C++ UnionFind解難題Leetcdoe 827 Making A Large Island
嘗試UnionFind解決。由於該題目透過最多翻轉 1 個額外的 0 單元來詢問最大島嶼的大小;使用Size優化而不是rank。
[Python解請進]
2025年1月19日 星期日
Python C++BFS /heap解Leetcode難題407 Trapping Rain Water II
Py3 cpp BFS /heap解Leetcode難題407 Trapping Rain Water II
解題要訣:boundary由外而內,容器採min heap,BFS走訪
[Py3解請進]
2025年1月11日 星期六
Python C++速解Leetcode迴文1400 Construct K Palindrome Strings
Python C++速解Leetcode迴文1400 Construct K Palindrome Strings
關鍵:偶數長度的回文字串中所有字母都出現偶數,奇數長度的回文字串中除了一個例外其他所有字母都出現偶數。
----------
The key observation: palindrome strings of even lengths have all letters even occurrences, palindrome strings of odd lengths have all letters even occurrences but except one letter with odd occurrence.
[Py3解答請進]
2025年1月3日 星期五
C++ python 用Prefix Sum速解Leetcode 2270 Number of Ways to Split Array
Prefix sum這個概念,只要數學會用Sigma的,問題都不大,基本上就是partial sum。程式要寫的好,老實講該有數學概念真不能少,演算法的東西畢竟是真刀真槍的。
C++ python 用Prefix Sum速解Leetcode 2270 Number of Ways to Split Array
求分割陣列 nums 的方式數量,使得 sum(nums[0...i]) \geq sum(nums[i+1...])。
如何?計算總和sum=sum(nums)
使用loop判斷i是否滿足sum(nums[0..i])\geq sum(nums[i..])=sum-sum(nums[0..i])
「Py3解請進」
訂閱:
文章 (Atom)
熱門文章
-
11!=?
-
產生50個元素的陣列並排序
-
輸出字串20次
-
計算你上學期加權平均
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
寫一個double-for迴圈,輸入n,其時間計算複雜度為O(nlog n)。 提示: C副程式時間複雜度O(n*log^2(n))
-
1. 利用遞迴input n算2^n 2. 用C算GCD(3333,456)
-
int a[]={21, 23, 57, 13 ,17, 6}; float average; average=?