Interview Questions

Identify the last character

2016-03-26  本文已影响15人  宋翰要长肉

Qestion

Algorithm

Code

public String doubleOrSingLastChar(int[] input) {
       int len = 8;
       int i = input.length - 8;
       if (input[i] == 1) {
           return "Double";
       }
       i -= len;
       int count = 0;
       while (i >= 0 && input[i] == 1) {
           count++;
           i -= len;
       }
       if (count % 2 == 1) {
           return "Double";
       } else {
           return "Single";
       }
   }

Complexity

上一篇下一篇

猜你喜欢

热点阅读