Back to project page androidcodes.
The source code is released under:
GNU General Public License
If you think the Android project androidcodes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.stacks; /*from www .j ava 2 s . c om*/ public class StockSpan { private int arr[] = { 10, 4, 5, 90, 120, 80 }; public void getSpan() { StackImpl s = new StackImpl<Integer>(); s.push(0); int stockSpanRes[] = new int[arr.length]; stockSpanRes[0] = 1; for (int i = 0; i < arr.length; i++) { while (!s.isEmpty() && arr[(int) s.peek()] <= arr[i]) { s.pop(); } stockSpanRes[i] = s.isEmpty() ? i + 1 : i - (int) s.peek(); s.push(i); } for (int i = 0; i < arr.length; i++) { System.out.println(stockSpanRes[i]); } } public static void main(String[] args) { StockSpan s = new StockSpan(); s.getSpan(); } }