Ad
  • Custom User Avatar

    minor feedback - instead of while(true) you could do this

    while(!node.equals(node.next)) {
      ...
    }
    return next;
    
  • Custom User Avatar

    2 suggestions

    • Specify the size of the ArrayList in its constructor
    • Inspired by some of the JS solutions, there's this idea using StringBuilder
       public String[] rotate(final String text) {
          final int len = text.length();
          final List<String> rotations = new ArrayList<>(len);
          final StringBuilder lastRotation = new StringBuilder(text);
          for (int i = 0; i < len; i++) {
             lastRotation.append(lastRotation.charAt(0)).deleteCharAt(0);
             rotations.add(lastRotation.toString());
          }
          return rotations.toArray(new String[len]);
       }
    
  • Custom User Avatar

    I'll bite - does it really matter that much in this case? lastRotation and i are both hoisted to function scope so I guess you could access it ahead of time - is that the concern?