GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/541_Reverse_String_II.java at master · iamsathish/leetcode Expand file tree/ Copy path541_Reverse_String_II.javaMore file actions 16 lines (16 loc) · 523 Bytes / Copy path541_Reverse_String_II.javaFile metadata and controls16 lines (16 loc) · 523 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution { public String reverseStr(String s, int k) { // https://leetcode.com/problems/reverse-string-ii/solution/ char[] a = s.toCharArray(); for (int start = 0; start < a.length; start += 2 * k) { int i = start, j = Math.min(start + k - 1, a.length - 1); // Reverse from i to j while (i < j) { char tmp = a[i]; a[i++] = a[j]; a[j--] = tmp; } } return new String(a); } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |