public class Main {
public String wordWrap(String[] words, int maxLen)
{
if(words == null || words.length == 0)
{
return null;
}
StringBuilder sb = new StringBuilder();
int current = 0;
int remain = maxLen;
for(int i = 0; i< words.length; i++)
{
if(words[i].length > remain)
{
break;
}
sb.append(words[i]).append("-");
remain -= words[i].length + 1;
}
sb.deleteCharAt(sb.length()-1);
return sb.toString();
}
}