big o - Calculating the Big O of this algorithm -


I wrote the following code to reverse the string: How do I calculate large o? This was an interview question for the status of a junior developer.

  public static zero reverse string (string stroke) {string reversed = ""; Int lastIndex = str.lastIndexOf (""); While (last indicator! = -1) {reverse = + str.substring (last index + 1) + ""; Str = str.substring (0, last index); Previousindex = str.lastIndexOf (""); } Reverse + = str; Println (reverse); }   

O (n) lastIndexOf .

Comments

Popular posts from this blog

Out of index C/C++ -

regex - PatternSyntaxException: while using String.ReplaceAll function in java? -

java - Projects which are accessed via multiple (different) IDEs: Ant or Maven? -