public class Solution { public ListbinaryTreeToLists(TreeNode root) { List res = new ArrayList<>(); if(root == null) { return res; } Queue queue = new LinkedList<>(); queue.offer(root); while(!queue.isEmpty()) { int levelNum = queue.size(); ListNode dummy = new ListNode(-1); ListNode tmp = dummy; //tmp -- the last ListNode for(int i = 0; i < levelNum; ++i) { TreeNode out = queue.poll(); pre.next = new ListNode(out.val); pre = pre.next; if(out.left != null) { queue.offer(out.left); } if(out.right != null) { queue.offer(out.right); } } res.add(dummy.next); } return res; } }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/77408.html
Valid Palindrome Problem Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Example A man, a plan, a canal: Panama is a palindrome. race a ca...
摘要:找到開(kāi)頭的某個(gè)進(jìn)行切割。剩下的部分就是相同的子問(wèn)題。記憶化搜索,可以減少重復(fù)部分的操作,直接得到后的結(jié)果。得到的結(jié)果和這個(gè)單詞組合在一起得到結(jié)果。 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome...
摘要:自己沒(méi)事刷的一些的題目,若有更好的解法,希望能夠一起探討項(xiàng)目地址 自己沒(méi)事刷的一些LeetCode的題目,若有更好的解法,希望能夠一起探討 Number Problem Solution Difficulty 204 Count Primes JavaScript Easy 202 Happy Number JavaScript Easy 190 Reverse Bi...
摘要:在線(xiàn)網(wǎng)站地址我的微信公眾號(hào)完整題目列表從年月日起,每天更新一題,順序從易到難,目前已更新個(gè)題。這是項(xiàng)目地址歡迎一起交流學(xué)習(xí)。 這篇文章記錄我練習(xí)的 LeetCode 題目,語(yǔ)言 JavaScript。 在線(xiàn)網(wǎng)站:https://cattle.w3fun.com GitHub 地址:https://github.com/swpuLeo/ca...我的微信公眾號(hào): showImg(htt...
摘要:月下半旬攻略道題,目前已攻略題。目前簡(jiǎn)單難度攻略已經(jīng)到題,所以后面會(huì)調(diào)整自己,在刷算法與數(shù)據(jù)結(jié)構(gòu)的同時(shí),攻略中等難度的題目。 Create by jsliang on 2019-07-30 16:15:37 Recently revised in 2019-07-30 17:04:20 7 月下半旬攻略 45 道題,目前已攻略 100 題。 一 目錄 不折騰的前端,和咸魚(yú)有什么區(qū)別...
閱讀 3274·2023-04-26 02:10
閱讀 2897·2021-10-12 10:12
閱讀 4596·2021-09-27 13:35
閱讀 1533·2019-08-30 15:55
閱讀 1076·2019-08-29 18:37
閱讀 3437·2019-08-28 17:51
閱讀 1971·2019-08-26 13:30
閱讀 1210·2019-08-26 12:09