麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

LintCode Search Graph Node

2019-11-10 20:32:14
字體:
來源:轉載
供稿:網友

Description: Given a undirected graph, a node and a target, return the nearest node to given node which value of it is target, return NULL if you can’t find.

There is a mapping store the nodes’ values in the given parameters.

Notice

It’s guaranteed there is only one available solution

Have you met this question in a real interview? Yes Example 2——3 5 / | | / | | / | | / | | 1 –4 Give a node 1, target is 50

there a hash named values which is [3,4,10,50,50], rePResent: Value of node 1 is 3 Value of node 2 is 4 Value of node 3 is 10 Value of node 4 is 50 Value of node 5 is 50

Return node 4

題目不難,直接食用正常的思路求解就可以

/** * Definition for graph node. * class UndirectedGraphNode { * int label; * ArrayList<UndirectedGraphNode> neighbors; * UndirectedGraphNode(int x) { * label = x; neighbors = new ArrayList<UndirectedGraphNode>(); * } * }; */public class Solution { /** * @params graph a list of Undirected graph node * @param values a hash mapping, <UndirectedGraphNode, (int)value> * @param node an Undirected graph node * @param target an integer * @return the a node */ public UndirectedGraphNode searchNode(ArrayList<UndirectedGraphNode> graph, Map<UndirectedGraphNode, Integer> values, UndirectedGraphNode node, int target) { // Write your code here if (node == null) { return null; } Queue<UndirectedGraphNode> queue = new LinkedList<>(); Set<UndirectedGraphNode> set =new HashSet<>(); queue.offer(node); set.add(node); while (!queue.isEmpty()) { UndirectedGraphNode gnode = queue.poll(); if (values.get(gnode) == target) { return gnode; } for (UndirectedGraphNode root : gnode.neighbors) { if (set.contains(root)) { continue; } queue.offer(root); set.add(root); } } return null; }}
上一篇:MFC指示燈學習

下一篇:線程安全

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 91精品国产92久久久久 | 在线视频观看国产 | 成人免费国产 | 国产精品999在线观看 | 视频毛片| 羞羞视频2023| 毛片在线视频免费观看 | 欧美一级高潮 | 成年人视频在线免费播放 | sese综合| 麻豆视频在线观看 | 校花被肉干高h潮不断 | 羞羞视频免费网站 | 福利在线国产 | 国产资源在线观看视频 | 精品一区二区6 | 国产成人精品免高潮在线观看 | 亚洲国产精品高潮呻吟久久 | 成人国产精品一区二区毛片在线 | 国产亚洲精品久久久久久久久 | 失禁高潮抽搐喷水h | 亚洲精品无码不卡在线播放he | 色综合久久久久综合99 | 欧美xxxxx视频 | 久久久久女人精品毛片九一 | 久久久久亚洲视频 | 黄色片一区二区 | 中文字幕在线视频日本 | hd极品free性xxx护士人 | 国产精品久久久免费观看 | 亚洲精品在线观看网站 | 欧美一级美片在线观看免费 | 激情视频在线播放 | 国产91精品亚洲精品日韩已满 | 欧美一级免费在线观看 | 日本高清在线免费 | 日本精品免费观看 | 国产在线观看91一区二区三区 | 中文字幕在线观看www | 国产午夜精品久久久 | 亚洲综合无码一区二区 |