686 Repeated String Match
1. Question
2. Implementation
class Solution {
public int repeatedStringMatch(String A, String B) {
int count = 0;
StringBuilder sb = new StringBuilder();
while (sb.length() < B.length()) {
sb.append(A);
++count;
}
if (sb.toString().indexOf(B) >= 0) {
return count;
}
if (sb.append(A).toString().indexOf(B) >= 0) {
return count + 1;
}
return -1;
}
}3. Time & Space Complexity
Last updated