diff --git a/src/Main.kt b/src/Main.kt index 4979bc1..0ee52fd 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -1,4 +1,4 @@ fun main() { - val t = Test560() + val t = Test14() t.test() } \ No newline at end of file diff --git a/src/Test14.kt b/src/Test14.kt new file mode 100644 index 0000000..109ddc8 --- /dev/null +++ b/src/Test14.kt @@ -0,0 +1,32 @@ +class Test14 { + class Solution { + fun longestCommonPrefix(strs: Array): String { + if (strs.size == 1){ + return strs[0] + } + var sb = strs[0] + for (s in strs){ + if (sb.isEmpty()){ + return "" + } + if (sb.lastIndex > s.lastIndex){ + sb = sb.substring(s.indices) + } + for (j in s.indices){ + if (j > sb.lastIndex){ + break + } + if (sb[j]!=s[j]){ + sb = sb.substring(0..