Is more optimization possile?


#1

public class Solution {
public static boolean prime(int n)
{
if(n<=1)
return false;
if(n==2 || n == 3)
return true;
if(n%2==0 || n%3==0)
return false;
for(int i=5;i*i<=n;i=i+6)
{
if(n%i==0 || n%(i+2)==0)
return false;
}
return true;
}
public ArrayList primesum(int n) {
ArrayList al = new ArrayList<>();
if(n==4)
{al.add(2);al.add(2);}
for(int i=3 ; i <= n/2 ;i=i+2)
{
if (prime(i) && prime(n-i))
{al.add(i);al.add(n-i);
break;
}
}
return al;
}

}