BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #53068同步于 2016/9/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

java链表求指导

bupt6394
2016/9/19镜像同步6 回复
刷leetcode的链表题直接跪了,怎么学链表啊? 发自「贵邮」
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
jaegerstar机器人#1 · 2016/9/19
搞好学数据结构
nuanyangyang机器人#2 · 2016/9/19
随便找一本数据结构的书看。
VictorLees机器人#3 · 2016/9/19
看看答案模仿记忆~
bh0机器人#4 · 2016/9/19
把链表题刷完 发自「贵邮」
sy24baba机器人#5 · 2016/9/19
leetcode链表的题目是所有类型里比较简单的啦
dss886机器人#6 · 2016/9/20
我们学校老师写的那本数据结构不是挺好懂的嘛,我记得作者是徐雅静? 我刷LeetCode的时候写了两个工具类,可以方便可视化的调试,供参考: Parser:https://github.com/dss886/LeetCode/blob/master/src/others/tool/Parser.java /** * Created by dss886 on 2016/5/15. */ public class Parser { /** * Example input: "[1, 2, 3, 4]" */ public static ListNode list(String list) { if (list == null || list.isEmpty()) return null; list = list.replaceAll("[\\[\\] ]", ""); String[] nums = list.split(","); ListNode head = new ListNode(Integer.parseInt(nums[0])); ListNode lastNode = head; for (int i = 1; i < nums.length; i++) { ListNode node = new ListNode(Integer.parseInt(nums[i])); lastNode.next = node; lastNode = node; } return head; } /** * Example input: "[1, 2, 3, 4, #, 5, #, 6, #, #, #, 7]" */ public static TreeNode tree(String tree) { if (tree == null || tree.isEmpty()) return null; tree = tree.replaceAll("[\\[\\] ]", "").replace("null", "#"); String[] nums = tree.split(","); TreeNode root = new TreeNode(Integer.parseInt(nums[0].trim())); buildTree(nums, root, 0); return root; } private static void buildTree(String[] nums, TreeNode node, int position) { int left = position * 2 + 1; int right = position * 2 + 2; if (left < nums.length && !nums[left].equals("#")) { node.left = new TreeNode(Integer.parseInt(nums[left])); buildTree(nums, node.left, left); } if (right < nums.length && !nums[right].equals("#")) { node.right = new TreeNode(Integer.parseInt(nums[right])); buildTree(nums, node.right, right); } } } Printer:https://github.com/dss886/LeetCode/blob/master/src/others/tool/Printer.java /** * Created by dss886 on 2016/5/15. */ public class Printer { public static void p(int content) { System.out.println(content); } public static void p(String content) { System.out.println(content); } public static void p(List content) { StringBuilder sb = new StringBuilder("["); for (Object s : content) { sb.append("\"").append(s).append("\", "); } int l = sb.length(); if (l > 1) sb.delete(l - 2, l); System.out.println(sb.append("]")); } public static void p(ListNode node) { StringBuilder sb = new StringBuilder(); if (node == null) { sb.append("null"); } else { while (node != null) { sb.append(node.val); if (node.next != null) sb.append("->"); node = node.next; } } System.out.println(sb.toString()); } }