😉 Welcome!

53. 最大子数组和

https://leetcode.cn/problems/maximum-subarray/ 1 2 3 4 5 6 7 8 9 10 11 class Solution { public: int maxSubArray(vector<int>& nums) { int ans = nums[0], cur = 0; for (int &x : nums) { cur = max(cur + x, x); ans = max(ans, cur); } return ans; } }; 1 2 3 4 5 6 7 class Solution: def maxSubArray(self, nums: List[int]) -> int: ans, cur = nums[0], 0 for x

121. 买卖股票的最佳时机

https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/ 1 2 3 4 5 6 7 8 9 10 11 class Solution { public: int maxProfit(vector<int>& prices) { int ans = 0, minPrice = prices[0]; for (int &price : prices) { ans = max(ans, price - minPrice); minPrice = min(minPrice, price); } return ans; } }; 1 2 3 4 5 6 7 class Solution: def maxProfit(self, prices: List[int]) -> int: ans, min_price = 0, prices[0] for price

高效的 Python 切片赋值

引言 对于某些算法题,可能需要维护一个有序的数据结构,而且需要查询中间满足某个条件的数据(如果是最小或最大值的话使用堆结构即可),C++ 中有 set/multiset/map/multimap

Hugo LoveIt 主题的使用

语法高亮 https://gohugo.io/content-management/syntax-highlighting/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ```go {linenos=table,hl_lines=[8,"15-17"],linenostart=199} // GetTitleFunc returns a func that can be used to transform a string to // title case. // // The supported styles are // // - "Go" (strings.Title) // - "AP" (see https://www.apstylebook.com/) // - "Chicago" (see https://www.chicagomanualofstyle.org/home.html) // // If