Skip to content

Instantly share code, notes, and snippets.

View codetalks-new's full-sized avatar
🏠
Working from home

codetalks codetalks-new

🏠
Working from home
  • China
View GitHub Profile
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)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@codetalks-new
codetalks-new / appIconize.sh
Created June 15, 2015 09:06
批量生成 iOS AppIcon 图标脚本
#!/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
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)
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{
// 没有子节点,访问此节点
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)
var cache = [Int:Int]()
func numTrees(n:Int) -> Int{
if n < 2{
return 1
}
if n == 2{
return 2
}
// 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
}
}
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {