在题目AcWing 1233. 全球变暖,y总的bfs函数是这样写的:
void bfs(int sx, int sy, int &total, int &bound)
加&的目的,就是为了让在bfs里的total和bound算完了能直接影响外面
那么,在go里要怎么写?
其实很简单,把total和bound设为公共变量就好:
var total, bound int
func bfs(sx, sy int) { // 在函数里就不用再传total和bound了
...
}
在题目AcWing 1233. 全球变暖,y总的bfs函数是这样写的:
void bfs(int sx, int sy, int &total, int &bound)
加&的目的,就是为了让在bfs里的total和bound算完了能直接影响外面
那么,在go里要怎么写?
其实很简单,把total和bound设为公共变量就好:
var total, bound int
func bfs(sx, sy int) { // 在函数里就不用再传total和bound了
...
}