Reverse a string in Java, in O(1)?

后端 未结 10 2030
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 01:47

Is there any facility in the standard Java libraries that, given a CharSequence, produces the reverse in O(1) time?

I guess this is \"easy\" to implement, just wond

10条回答
  •  忘掉有多难
    2020-12-31 02:16

    StringBuffer has a reverse: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html#reverse()

    BTW, I assume you meant O(n) because O(1) (as other people have mentioned) is obviously impossible.

提交回复
热议问题