jdk8 indexOf时间复杂度

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29697901/article/details/87882690
for (int i = sourceOffset + fromIndex; i <= max; i++) {
            /* Look for first character. */
            if (source[i] != first) {
                while (++i <= max && source[i] != first);
            }

            /* Found first character, now look at the rest of v2 */
            if (i <= max) {
                int j = i + 1;
                int end = j + targetCount - 1;
                for (int k = targetOffset + 1; j < end && source[j]
                        == target[k]; j++, k++);

                if (j == end) {
                    /* Found whole string. */
                    return i - sourceOffset;
                }
            }
        }

jdk8 中的部分源码,没有任何算法,直接暴力比较,先比较第一个字符,接着比较第二个,时间复杂度为 O(m*n)

猜你喜欢

转载自blog.csdn.net/qq_29697901/article/details/87882690