Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- enum VisitType { NONE, WEB, APP }
- public int solve(int[] A, int[] B) {
- int count = 0;
- int i = 0, j = 0;
- VisitType prev = VisitType.NONE;
- while (i < A.length && j < B.length) {
- if (A[i] < B[j]) {
- if (prev == VisitType.APP)
- count++;
- prev = VisitType.WEB;
- i++;
- } else {
- if (prev == VisitType.WEB)
- count++;
- prev = VisitType.APP;
- j++;
- }
- }
- if (i < A.length && prev == VisitType.APP ||
- j < B.length && prev == VisitType.WEB)
- count++;
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement