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

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -