This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func levelOrderTraversal(root:TreeNode) -> [[Int]]{ | |
var outerArr = [[Int]]() | |
var levelNode = [TreeNode]() | |
var nextLevelNode = [TreeNode]() | |
levelNode.append(root) | |
var innerArr = [Int]() | |
while !levelNode.isEmpty{ | |
let currentNode = levelNode.removeAtIndex(0) | |
innerArr.append(currentNode.val) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo mkdir | |
rmdir -rf appIcons | |
mkdir appIcons | |
echo resize icon $1 | |
img=$1 | |
#IFS='.' read -ra fcomps <<< "$img" | |
#echo fcomps is ${fcomps[@]} | |
#compsCount=${#fcomps[@]} | |
#echo comps count $compsCount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func maxDepth_r(root:TreeNode?) -> Int{ | |
if root == nil{ | |
return 0 | |
} | |
if root?.left == nil && root?.right == nil{ | |
return 1 | |
} | |
let rightDepth = maxDepth_r(root?.left) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postorderTraversal(root:TreeNode) -> [Int]{ | |
var arr = [Int]() | |
var nodes = [TreeNode]() | |
var middleNodes = [TreeNode]() | |
var current :TreeNode? = root | |
var lastMiddleNode : TreeNode? | |
while current != nil{ | |
let cur = current! | |
if cur.left == nil && cur.right == nil{ | |
// 没有子节点,访问此节点 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func preorderTraversal(root:TreeNode) -> [Int]{ | |
var arr = [Int]() | |
var nodes = [TreeNode]() | |
nodes.append(root) | |
while !nodes.isEmpty{ | |
let current = removeLast(&nodes) | |
arr.append(current.val) | |
if let right = current.right{ | |
nodes.append(right) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cache = [Int:Int]() | |
func numTrees(n:Int) -> Int{ | |
if n < 2{ | |
return 1 | |
} | |
if n == 2{ | |
return 2 | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/binary-tree-inorder-traversal/ | |
class TreeNode{ | |
let val:Int | |
var left:TreeNode? | |
var right:TreeNode? | |
init(val:Int){ | |
self.val = val | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |