From 9ad87617a05ab622b665401969f560da37db5fad Mon Sep 17 00:00:00 2001 From: krahets Date: Wed, 15 Feb 2023 03:24:26 +0800 Subject: [PATCH] Add missing Vertex.java --- codes/java/include/Vertex.java | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 codes/java/include/Vertex.java diff --git a/codes/java/include/Vertex.java b/codes/java/include/Vertex.java new file mode 100644 index 000000000..80c59cfd8 --- /dev/null +++ b/codes/java/include/Vertex.java @@ -0,0 +1,35 @@ +/** + * File: TreeNode.java + * Created Time: 2022-11-25 + * Author: Krahets (krahets@163.com) + */ + +package include; + +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 vetsToVals(List vets) { + List vals = new ArrayList<>(); + for (Vertex vet : vets) { + vals.add(vet.val); + } + return vals; + } +} \ No newline at end of file