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
Sun, Apr 26, 1:02 PM (1 d, 2 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
27/8b/62b77fed6da17f7f91b7d1062a87

Event Timeline