Scala for loop
Scala for loop statement
1
import scala.collection.mutable.ArrayBuffer
2
def findTripletSumZero(arr: Array[Int]): Array[Array[Int]]={
3
var ret=ArrayBuffer[Array[Int]]()
4
var inter=ArrayBuffer[Int]()
5
6
for (i<-0 until arr.length)
7
for (j<-i until arr.length)
8
if (j+1<arr.length)
9
if (arr(i)+arr(j)+arr(j+1)==0)
10
{
11
inter+=arr(i)
12
inter+=arr(j)
13
inter+=arr(j+1)
14
ret+=inter.toArray
15
inter=ArrayBuffer[Int]()
16
}
17
ret.toArray
18
}
Copied!
Last modified 1yr ago
Copy link