作者归档:在线疯狂

RSS feed of 在线疯狂

[LeetCode]Power of Three

题目描述:

Given an integer, write a function to determine if it is a power of three.

Follow up:

Could you do it without using any loop / recursion?

题目大意:

给定一个整数,编写函数判断它是否是3的幂。

进一步思考:

你可以不用循环/递归解出本题吗?

解题思路:

解法I:求对数,然后乘方,判断得数是否相等

Python代码:

class ...

继续阅读

[LeetCode]Sum Root to Leaf Numbers

题目描述:

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

An example is the root-to-leaf path 1->2->3 which represents the number 123.

Find the total sum of all root-to-leaf numbers.

For example,

    1 ...

继续阅读

HTML5+JavaScript实现雪花飘落特效

下面的JavaScript代码利用HTML5 canvas实现了动态的雪花飘落效果,CPU开销也比较小。

原文链接:http://www.oschina.net/code/snippet_436266_46013

JavaScript代码:

<canvas id="christmasCanvas" style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;" ></canvas>
<script type="text/javascript">
  var snow = function() {
    if(1==1) {
      var ...

继续阅读