CRNN OCR在档案管理的应用:老旧文件数字化方案
2026/1/9 23:13:54
这道题最优解是使用单调栈(Monotonic Stack)。
核心思想:
为什么是 O(n)?
class Solution { public int[] dailyTemperatures(int[] temperatures) { int n=temperatures.length; Stack<Integer> stack =new Stack<>(); int[] res=new int[n]; for(int i=0;i<n;i++){ while(!stack.isEmpty()&&temperatures[i]>temperatures[stack.peek()]){ int a=stack.pop(); res[a]=i-a; } stack.push(i); } res[n-1]=0; return res; } }