I have java code like the following:
class Solution {
public String longestCommonPrefix(String[] strs) {
// Argument checks
if (strs == null || strs.length == 0) return "";
if (strs.length == 1) return strs[0];
StringBuilder sb = new StringBuilder();
Arrays.sort(strs);
char[] first = strs[0].toCharArray();
char[] last = strs[strs.length - 1].toCharArray();
for (int i = 0, j = 0; i < first.length && j < last.length; i++, j++) {
if (first[i] != last[j]) break;
sb.append(first[i]);
}
return sb.toString();
}
}
My question is how I write for loop like for (int i = 0, j = 0; i < first.length && j < last.length; i++, j++) in Kotlin? Thanks!
===== Update ======== 29 July 2022
I think I am providing a bad code example here... please focus on the question: how I write for loop like for (int i = 0, j = 0; i < first.length && j < last.length; i++, j++) in Kotlin?