Hawstein's Blog

Make something people love

Cracking the coding interview--Q3.2

题目 原文: How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time. 译文: 实现一个栈,...

Cracking the coding interview--Q3.1

题目 原文: Describe how you could use a single array to implement three stacks. 译文: 你如何只用一个数组实现三个栈? 解答 我们可以很容易地用一个数组来实现一个栈,压栈就往数组里插入值,栈顶指针加1; 出栈就直接将栈顶指针减1;取栈顶值就把栈顶指针指向的单元的值返回; 判断是否为空就直接看栈顶指针是否为-1...

Cracking the coding interview--Q2.5

题目 原文: Given a circular linked list, implement an algorithm which returns node at the beginning of the loop. DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next po...

Cracking the coding interview--Q2.4

题目 原文: You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Wr...

Cracking the coding interview--Q2.3

题目 原文: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node. EXAMPLE Input: the node ‘c’ from the linked list a->b->c->d->e...

限制你上某些网站的Chrome插件——Website Postponer

layout: post category: Programming title: — 前言 写这样一个插件的想法是在某一天睡觉的时候产生的。为的是解决生活中遇到的一个问题—— 刷微博(目测还有人人网)。我一天大部分的时间都在实验室里,看论文,写程序,做项目, 作为一个CSer,终日与电脑为伴。有时候,我回顾过去的一天,会发现有许多的时间都浪费 在漫无目的的网页浏览上了,尤其是在微博...

Cracking the coding interview--Q2.2

题目 原文: Implement an algorithm to find the nth to last element of a singly linked list. 译文: 实现一个算法从一个单链表中返回倒数第n个元素。 解答 这道题的考点在于我们怎么在一个单链表中找到倒数第n个元素? 由于是单链表,所以我们没办法从最后一个元素数起,然后数n个得到答案。 但这种最直观的...

Cracking the coding interview--Q2.1

题目 原文: Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve this problem if a temporary buffer is not allowed? 译文: 从一个未排序的链表中移除重复的项 进一步地, 如果不允许使用临时的缓存...

Cracking the coding interview--Q1.8

题目 原文: Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call t...

Cracking the coding interview--Q1.7

题目 原文: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 译文: 写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0. 解答 简单题。遍历一次矩阵,当遇到元素等于0时,记录下这个元...