How to determine the set is symmetric using java code?
import java.util.LinkedList;
public class Main {
public static boolean isSymmetric(LinkedList<int[]> relations) {
for (int[] relation : relations) {
if (relation[0] != relation[1]) {
boolean symmetric = false;
for (int[] relationB : relations) {
if (relationB[0] == relation[1] && relationB[1] == relation[0]) {
symmetric = true;
break;
}
}
if (!symmetric) {
return false;
}
}
}
return true;
}
}
Comments
Leave a comment