3.λ.形而下技术博客

这里只关注技术实现,用代码说话。

0%

题目概述

原题链接

Given a nested list of integers, implement an iterator to flatten it.

Each element is either an integer, or a list – whose elements may also be integers or other lists. Input: [[1,1],2,[1,1]] Output: [1,1,2,1,1]

阅读全文 »

题目概述

原题链接

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.
Determine the maximum amount of money the thief can rob tonight without alerting the police.
1
2
3
4
5
6
7
Example 1:
3
/ \
2 2
\ \
4 1
Maximum amount of money the thief can rob = 3 + 4 + 1 = 8.
阅读全文 »

问题

这是一个经典题,面试的时候经常会遇到。 例如:文件的内容如下

26329
46184
94842
9036
96555
40954
38187
15548
51452
861
51010
8721
13666
69837 

每行一个数字,找到出现次数最多的数。通常的解法是遍历文件一遍,用hashmap维护一个(number => freq), 然后用最小堆找到最大的10个数。

阅读全文 »

题目概述

312原题链接

Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.

Find the maximum coins you can collect by bursting the balloons wisely.

examples:
nums = [3,1,5,8] --> [3,5,8] -->   [3,8]   -->  [8]  --> []
coins =  3*1*5      +  3*5*8    +  1*3*8      + 1*8*1   = 167
阅读全文 »

问题

Java世界里构建项目用什么工具呢,ant,maven和gradle。maven非常流行, 原因无非是maven仓库和项目架构的约定。但是ant构建过程更加容易理解, 因为ant展示了所有的操作。gradle拥有基于groovy语言的DSL语言且继承了 maven仓库的思想所以笔者认为未来是属于gradle的。

阅读全文 »

MiniLisp是什么?

MiniLisp是一个只用几百行代码实现的Lisp。以下是实现的 基本特性。

  • integers, symbols, cons cells,
  • global variables,
  • lexically-scoped local variables,
  • closures,
  • if conditional,
  • primitive functions, such as +, =, <, or list,
  • user-defined functions,
  • a macro system,
  • and a copying garbage collector.
阅读全文 »