摘要: Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) Yo 阅读全文
posted @ 2019-07-13 10:00 bossman 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward 阅读全文
posted @ 2019-07-12 22:27 bossman 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given the root of a binary tree, each node in the tree has a distinct value. After deleting all nodes with a value in to_delete, we are left with a fo 阅读全文
posted @ 2019-07-11 23:55 bossman 阅读(403) 评论(0) 推荐(0) 编辑
摘要: Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w 阅读全文
posted @ 2019-07-11 22:46 bossman 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to le 阅读全文
posted @ 2019-07-11 20:14 bossman 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3 阅读全文
posted @ 2019-07-11 19:23 bossman 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Example 1: Example 2: Note: 典型的DFS,跟之前的一个手机键盘拨号很像 BFS Solution: 更短的DFS解法,加上一个path代表遍历的路径(classic dfs),最后对比路径的长度与房间的总数: 更短的BFS: 阅读全文
posted @ 2019-07-10 11:32 bossman 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 题目描述: Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the g 阅读全文
posted @ 2019-07-09 20:46 bossman 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest le 阅读全文
posted @ 2019-07-08 17:50 bossman 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 每次调用dfs函数,得到返回值的时候就是加入新解的时候,根据depth来判断这个解属于新的一层还是已有层。此题的逻辑非常符合深度优先搜索的本质:到达叶子节点后逐级回溯 阅读全文
posted @ 2019-07-08 14:13 bossman 阅读(291) 评论(0) 推荐(0) 编辑