[GO] Array and string - Two-pointer Technique - Scenario I
Reverse the elements in an array. Java public static void reverse(int[] v, int N) { int i = 0; int j = N - 1; while (i < j) { swap(v, i, j); // this is a self-defined function i++; j--; } } GO func reverse(v []int, N int) { var i int = 0 var j = N - 1 for i < j { swap(v, i, j) // this is a self-defined function i++ j-- } }
Go/Leet Code
2022. 4. 9. 17:46