Page MenuHomedesp's stash

Solution.java
No OneTemporary

Solution.java

public class Solution {
public static int solution(String x) {
//assume entire cake can be fully split
for(int i = x.length() - 1; i > 0; i--) { //max amount of slices will be the same even if we rotate the cake
int t = countSlice(x.split(x.substring(i), -1)); //slice the cake and count the slices
if(t != -1) return t; //smallest slice is always the most possible slice; return on first valid slice and stop
}
return 1; //if no slices are valid returns the lowest possible slice, aka the entire cake
}
public static int countSlice(String[] split) {
for(String s : split) { //if not empty it means there are leftovers; Lambda would be enraged
if(!s.isEmpty()) return -1; //stop and return invalid count
}
return split.length - 1; //valid slices; check count from split tokens
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 27, 8:07 PM (16 h, 42 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
69/d4/ee98c077027b12cfd78559963bb1

Event Timeline