/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年6月8日 星期一

0ms branchless|C++ Py3 2-pointer速解Leetcode 2161 Partition Array According to Given Pivot


C++ Py3 2pointer速解Leetcode2161  Partition Array According to Given Pivot
影片說明解法Py3用迴圈 list 相加。
[C++branchless 0ms請進]
----
The video explains the solution in Py3 using a loop to add lists. (C++ branchless, 0ms)
---
Time stamps:
0:00 - Introduction and Problem Overview (LeetCode 2161)
0:45 - Explaining the Problem Requirements and Conditions
3:06 - Example 1 Walkthrough
3:56 - Example 2 Walkthrough
4:33 - Python 3 Solution Implementation and Explanation
6:12 - Python 3 Code Submission and Performance Result
6:32 - C++ Solution Implementation (Branchless Approach)
8:33 - C++ Code Submission and Performance Result (0ms)
 #anwendeng
class Solution {
public:
    static vector<int> pivotArray(vector<int>& nums, int pivot) {
        int n=nums.size();
        if (n==1) return nums;
        int R[n];
        int l=0, r=0;
        for(int x: nums){
            nums[l]=R[r]=x;
            l+=(x<pivot);
            r+=(x>pivot);
        }
        int m=n-r-l;
        auto it_m=nums.begin()+l;
        fill(it_m, it_m+m, pivot);
        copy(R, R+r, it_m+m);
        return nums;
    }
};

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章