@@ -0,0 +1,2557 @@
+//  Copyright 2021 The KeepTry Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0Apackage list;%0A%0Aimport java.util.Stack;%0A%0Apublic class VersionCompareTailList %7B%0A  /*%0A  Question 1%0A  compare 2 version in string%0A    %222.3.0%22 == %222.3%22%0A    %222.3.1%22  %3E %222.3%22%0A  Need append zero to make same length which can be applied in loop%0A  */%0A  public int compare(String v1, String v2) %7B%0A    if (v1 == null && v2 == null) return 1;%0A    if (v1 == null) return -1;%0A    if (v2 == null) return 1;%0A%0A    String%5B%5D p1 = v1.split(%22%5C%5C.%22, -1);%0A    String%5B%5D p2 = v2.split(%22%5C%5C.%22, -1);%0A    for (int i = 0; i %3C p1.length %7C%7C i %3C p2.length; i++) %7B%0A      int n1 = i %3C p1.length ? Integer.valueOf(p1%5Bi%5D) : 0;%0A      int n2 = i %3C p2.length ? Integer.valueOf(p2%5Bi%5D) : 0;%0A      if (n1 %3C n2) return -1;%0A      if (n1 %3E n2) return 1;%0A    %7D%0A    return 0;%0A  %7D%0A%0A  /*---------------------------------------------------------------------------*/%0A  static class Node %7B%0A    public Node next;%0A    public int v;%0A%0A    public Node(int v, Node next) %7B%0A      this.v = v;%0A      this.next = next;%0A    %7D%0A  %7D%0A  /*%0A   Question 2%0A      1-%3E 2 -%3E 3%0A      5-%3E 8 -%3E 1-%3E2-%3E3%0A      output 2, the o-based index of one list in the another list as the suffix%0A      1-%3E 2 -%3E 3%0A      5-%3E 8 -%3E 1-%3E2-%3E3 -%3E 8%0A      output null: one list must be tail of another list%0A%0A   Need append zero to make same length which can be applied in loop%0A%0A  */%0A  // O(N) space and time%0A  public static Integer oneIsSuffix(Node a, Node b) %7B%0A    if (a == null %7C%7C b == null) return null;%0A    Stack%3CInteger%3E as = new Stack%3C%3E(), bs = new Stack%3C%3E();%0A    int la = 0, lb = 0;%0A    while (a != null %7C%7C b != null) %7B%0A      if (a != null) %7B%0A        as.push(a.v);%0A        a = a.next;%0A        la++;%0A      %7D%0A      if (b != null) %7B%0A        bs.push(b.v);%0A        b = b.next;%0A        lb++;%0A      %7D%0A    %7D%0A    while (!as.isEmpty() && !bs.isEmpty() && as.peek() == bs.peek()) %7B%0A      as.pop();%0A      bs.pop();%0A      la--;%0A      lb--;%0A    %7D%0A    if (as.isEmpty() %7C%7C bs.isEmpty()) %7B%0A      return as.isEmpty() ? lb : la;%0A    %7D%0A    return null;%0A  %7D%0A%7D%0A

version compare