mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-27 01:16:29 +08:00
37 lines
816 B
Java
37 lines
816 B
Java
|
/**
|
||
|
* File: Vertex.java
|
||
|
* Created Time: 2023-02-15
|
||
|
* Author: krahets (krahets@163.com)
|
||
|
*/
|
||
|
|
||
|
package utils;
|
||
|
|
||
|
import java.util.*;
|
||
|
|
||
|
/* 頂點類別 */
|
||
|
public class Vertex {
|
||
|
public int val;
|
||
|
|
||
|
public Vertex(int val) {
|
||
|
this.val = val;
|
||
|
}
|
||
|
|
||
|
/* 輸入值串列 vals ,返回頂點串列 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;
|
||
|
}
|
||
|
|
||
|
/* 輸入頂點串列 vets ,返回值串列 vals */
|
||
|
public static List<Integer> vetsToVals(List<Vertex> vets) {
|
||
|
List<Integer> vals = new ArrayList<>();
|
||
|
for (Vertex vet : vets) {
|
||
|
vals.add(vet.val);
|
||
|
}
|
||
|
return vals;
|
||
|
}
|
||
|
}
|