Fish
1 /// <summary> 2 /// Solution 3 /// 100/100 4 /// </summary> 5 /// <param name="A"></param> 6 /// <param name="B"></param> 7 /// <returns></returns> 8 public static int solution(int[] A, int[] B) 9 { 10 Stack<int> up = new Stack<int>(); 11 Stack<int> down = new Stack<int>(); 12 for (int i = 0; i < A.Length; i++) 13 { 14 if (B[i] == 1) 15 down.Push(A[i]); 16 17 if (B[i] == 0) 18 { 19 if (down.Count == 0) 20 { 21 up.Push(A[i]); 22 } 23 else 24 { 25 while (down.Count > 0) 26 { 27 if (down.Peek() > A[i]) 28 break; 29 else 30 down.Pop(); 31 } 32 if (down.Count == 0) 33 up.Push(A[i]); 34 } 35 } 36 } 37 return up.Count + down.Count; 38 }