977.有序数组的平方 ,209.长度最小的子数组 ,59.螺旋矩阵II
977.有序数组的平方 ,209.长度最小的子数组 ,59.螺旋矩阵II
977.有序数组的平方
思路:
分别 从 数组 的 左 , 右 向 另一侧 / 中间 趋近,
新 建立 一个 数组 接收 (有序 序列) (动态 地 在 过程 中 接收 数据)
拓展 为 各个 任务 分配 工作 指针 , 形成 多指针
有序 数字 序列 ,使用 双指针 从 两侧 趋近 , 可以 有效 地 转化 为 绝对值 序列 , (从 放置 “大” 绝对值 得 位置 开始 写入 (可以 是 从右往左))
vector<int> sortedSquares(vector<int>& nums) {
        int len = end(nums) - begin(nums);
        int i = 0;
        int j = len - 1 ;
        int k = len - 1;
        vector<int> TempReceive(len,0); 
        int Temp_Cache_Left = nums[i]*nums[i];
        int Temp_Cache_Right = nums[j]*nums[j];
        while(i <= j)
        {
            //内循环
            if((Temp_Cache_Left) >= (Temp_Cache_Right)        )         // 基础逻辑  与  代码 优化           
            {
                TempReceive[k] = Temp_Cache_Left;
                k--;
                i++;
                if(i < len)         //防 溢出
                {   
                    Temp_Cache_Left = nums[i]*nums[i];
                }
            }
            else
            {
                TempReceive[k] = Temp_Cache_Right;
                k--;
                j--;
                if(j >= 0 )
                {
                    Temp_Cache_Right = nums[j]*nums[j];
                }
            }
        }
        return TempReceive;
    }
209.长度最小的子数组
int minSubArrayLen(int target, vector<int>& nums) {
        int len = end(nums) - begin(nums);
        int i = 0; 
        int j = -1;
        int sum = 0;
        int tempSum = 0;
        // “ j  “轮个” 查询 ”
        // i 趋近 到 不能 趋近 的 程度
        int temp_mini_len = -1;
        int Cache_Target_len = 0;
                    // “快速 略过 / 跳过 sum 还 不满足 时 的 情况”
        
        do
        {
            j++;
            if(j >= len)
            {
                break;
            }
            else
            {
                tempSum = tempSum + nums[j];
            }
            
        }while(j<len && tempSum < target );
        if(j<len)       // 防  溢出    ,  注意 边界 
        {
            if(tempSum >= target)
            {
                Cache_Target_len = j - i +1;
            }
        
            do
            {
                //内循环
                // 预处理 操作 / 操作区
                while( i < j )
                {
                    tempSum = tempSum - nums[i];
                    if(tempSum >= target)
                    {
                        // Storage 
                        // Update i ;
                        i++;
                        //keep check
                    }
                    else
                    {
                        tempSum = tempSum + nums[i];        // 回 退 操作
                        break;
                    }
                }
                temp_mini_len = (j - i + 1);
                if(temp_mini_len < Cache_Target_len)
                {
                    Cache_Target_len = temp_mini_len;
                }
                if(j+1 < len)
                {
                    j++;
 
                     
                    
                 
                    
                