herrDeng網內搜尋

自訂搜尋

Ads

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解請進」

2024年12月27日 星期五

C++Python Greedy DP速解Leetcode 1014 Best Sightseeing Pair


C++Python Greedy DP速解Leetcode 1014  Best Sightseeing Pair算是貪婪演算還是動態規劃,其實都算解法類似Kadane演算法。
-----------
Leetcode 1014. Best Sightseeing Pair is considered greedy algorithm or dynamic programming, but it is actually both. It's similar to Kadane's Algorithm
[Py3 解答請進]

python Keras使用仿AlexNet針對oxflower達到100趴的辨識率實測

2024年12月23日 星期一

C++BFS走訪 level排序與DFS cycle長度計數解Leetcode 2471 Minimum Number of Operatio...


C++BFS走訪 level排序與DFS cycle長度計數解Leetcode 2471  Minimum Number of Operations to Sort a Binary Tree by Level
解圖論問題Leetcode 2471. Minimum Number of Operations to Sort a Binary Tree by Level,這不算稀奇,但當中還用到置換群(permutation group)的概念就比較特別。
------
Solve the graph theory problem Leetcode 2471. Minimum Number of Operations to Sort a Binary Tree by Level. This is not unusual, but the concept of permutation group is also used in it, which is quite special.
Related Posts Plugin for WordPress, Blogger...

熱門文章