classSolution{publicint[]dailyTemperatures(int[] temperatures){int n = temperatures.length;int[] ans =newint[n];Stack<Integer> stack =newStack<>();stack.push(0);for(int i =1; i < n; i++){if(temperatures[i]<= temperatures[stack.peek()])stack.push(i);else{while(!stack.isEmpty()&& temperatures[i]> temperatures[stack.peek()]){ans[stack.peek()]= i - stack.pop();}stack.push(i);}}return ans;}}
496.下一个更大元素 I
classSolution{publicint[]nextGreaterElement(int[] nums1,int[] nums2){Stack<Integer> stack =newStack<>();int[] ans =newint[nums1.length];Arrays.fill(ans,-1);Map<Integer,Integer> map =newHashMap<>();for(int i =0; i < nums1.length; i++)map.put(nums1[i], i);stack.push(0);for(int i =1; i < nums2.length; i++){if(nums2[i]<= nums2[stack.peek()])stack.push(i);else{while(!stack.isEmpty()&& nums2[i]> nums2[stack.peek()]){if(map.containsKey(nums2[stack.peek()])){ans[map.get(nums2[stack.peek()])]= nums2[i];}stack.pop();}stack.push(i);}}return ans;}}
CUDA 运行时 API 与 CUDA 驱动 API 速度没有差别,实际中使用运行时 API 较多,运行时 API 是在驱动 API 上的一层封装。
CUDA 是什么?
CUDA(Compute Unified Device Architecture) 是 nvidia 推出的一个通用并行技术架构,用它…