Domanda di colloquio di Addepar

How do you reverse a string in place

Risposte di colloquio

Anonimo

27 feb 2019

private static String reverseString(String str) { char[] chars = str.toCharArray(); int s = 0; int e = chars.length - 1; while (s < e) { char tmp = chars[s]; chars[s] = chars[e]; chars[e] = tmp; s++; e--; } return new String(chars); }

Anonimo

27 feb 2019

```private static String reverseString(String str) { char[] chars = str.toCharArray(); int s = 0; int e = chars.length - 1; while (s < e) { char tmp = chars[s]; chars[s] = chars[e]; chars[e] = tmp; s++; e--; } return new String(chars); }```