题意:给定一棵二叉树,返回按zigzag层次遍历的结果
思路:
还是跟前面的Binary Tree Level Order Traversal的思路一样
即从上往下按层遍历二叉树,将每一层的节点存放到该层对应的数组中
最后将得到的总数组中奇数层(从0层开始计数)的子数组reverse一下就可以了
复杂度:时间O(n),空间O(n)...
分类:
其他好文 时间:
2014-05-15 15:15:50
阅读次数:
374
Given an array of integers, every element appears twice except for one. Find that single one....
分类:
其他好文 时间:
2014-05-15 07:20:39
阅读次数:
264
【题目】
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Out...
分类:
其他好文 时间:
2014-05-15 05:13:49
阅读次数:
306
LeetCode-001 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2...
分类:
其他好文 时间:
2014-05-15 04:34:50
阅读次数:
293
std::auto_ptr 析构的时候调用 delete
操作符来自动释放所包含的对象boost::scoped_ptr / boost::scoped_array不能传递它所包含的对象的所有权
到另一个作用域指针boost::shared_ptr /boost::shared_array在内部记录...
分类:
其他好文 时间:
2014-05-15 02:01:07
阅读次数:
353
Best Time to Buy and Sell Stock1Say you have an
array for which theithelement is the price of a given stock on dayi.If you were
only permitted to comp...
分类:
其他好文 时间:
2014-05-14 22:36:11
阅读次数:
353
题意:从一个已排序的数组中移除掉重复的元素,每个元素最多可重复两次
思路: 思路和Remove Duplicates from Sorted Array一样,不过要设置一个计数变量,表示当前值出现的次数
出现次数少于2可以加入到新数组,多于2则不可以。每次遇到一个新变量要把计数变量重新设置为1,加入新数组要加1
复杂度:时间O(n), 空间O(1)...
分类:
其他好文 时间:
2014-05-14 21:03:00
阅读次数:
262
获取服务器mac
<?php
/**
获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回带有MAC地址的字串数组
var $macAddr;
/*构造*/
function __construct($...
分类:
Web程序 时间:
2014-05-14 20:48:33
阅读次数:
387
【题目】
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
【题意】
反转int型整数,输出的也是int型的整数
【思路】
如要考虑两种特殊情况:
1. 类似100这样的整数翻转之后为1
2. 翻转之后的值溢出该如何处理,
本题的测试用例中似乎没有给出溢出的情况
...
分类:
其他好文 时间:
2014-05-14 20:41:19
阅读次数:
244
Total Accepted: 8400 Total Submissions: 38235 My Submissions
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profi...
分类:
其他好文 时间:
2014-05-14 19:39:53
阅读次数:
275