You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
840 B
37 lines
840 B
6 months ago
|
/**
|
||
|
* File: Vertex.java
|
||
|
* Created Time: 2023-02-15
|
||
|
* Author: krahets (krahets@163.com)
|
||
|
*/
|
||
|
|
||
|
package utils;
|
||
|
|
||
|
import java.util.*;
|
||
|
|
||
|
/* Vertex class */
|
||
|
public class Vertex {
|
||
|
public int val;
|
||
|
|
||
|
public Vertex(int val) {
|
||
|
this.val = val;
|
||
|
}
|
||
|
|
||
|
/* Input a list of values vals, return a list of vertices vets */
|
||
|
public static Vertex[] valsToVets(int[] vals) {
|
||
|
Vertex[] vets = new Vertex[vals.length];
|
||
|
for (int i = 0; i < vals.length; i++) {
|
||
|
vets[i] = new Vertex(vals[i]);
|
||
|
}
|
||
|
return vets;
|
||
|
}
|
||
|
|
||
|
/* Input a list of vertices vets, return a list of values vals */
|
||
|
public static List<Integer> vetsToVals(List<Vertex> vets) {
|
||
|
List<Integer> vals = new ArrayList<>();
|
||
|
for (Vertex vet : vets) {
|
||
|
vals.add(vet.val);
|
||
|
}
|
||
|
return vals;
|
||
|
}
|
||
|
}
|