상세 컨텐츠

본문 제목

[GO] Array and string - Two-pointer Technique - Scenario I

Go/Leet Code

by Gopythor 2022. 4. 9. 17:46

본문

728x90
반응형

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--
	}
}
728x90
반응형

관련글 더보기

댓글 영역