- 博客(14)
- 资源 (20)
- 收藏
- 关注
原创 Top 150 Questions - 2.5
2.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 pointer point
2012-04-30 16:07:46 1008 1
原创 Top 150 Questions - 2.4
2.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. Write a func
2012-04-30 10:40:50 892
原创 Top 150 Questions - 2.3
2.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; Result: nothing is r
2012-04-25 00:05:42 927
原创 Top 150 Questions - 2.2
2.2 Implement an algorithm to find the nth to last element of a singly linked list.两个指针间距n-1,后一个指针走到底时返回第一个指针即可,注意要检查cur是否为空,防止n过大。package Question2_2;public class Question2_2{ public stat
2012-04-24 23:38:01 838
原创 Top 150 Questions - 2.1
2.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?RemoveDuplicate1()使用了Java的Hashtable,如果发现了duplicate,
2012-04-24 22:52:58 1016
原创 Top 150 Questions - 1.8
1.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 to isSubstr
2012-04-23 23:13:22 886
原创 Top 150 Questions - 1.7
1.7 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.SetZero1()先扫描一次数组,记录下0元素的位置,然后进行设置。由于行列同时记录,那么同一行或列可能被设置多次,因此在SetZero2()中对行列分开存储。package
2012-04-16 12:38:44 828
原创 Top 150 Questions - 1.6
1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?这个题看到4 bytes的时候以为要考移植性,不过既然用java
2012-04-16 10:37:18 1035
原创 Top 150 Questions - 1.5
1.5 Write a method to replace all spaces in a string with ‘%20’.package Question1_5;public class Question1_5{ public static void main(String[] args) { Question1_5 q = new Question1_5();
2012-04-15 17:41:54 1107
原创 Top 150 Questions - 1.4
1.4 Write a method to decide if two strings are anagrams or not.这个题目最简单的方法应该就是排序了吧,排序偷懒了,直接用的api;另外一个就是计算每个字符出现的次数。package Question1_4;import java.util.Arrays;public class Question1_4{
2012-04-15 17:09:57 4071 1
原创 Top 150 Questions - 1.3
1.3 Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is
2012-04-15 15:58:50 1183 2
原创 Top 150 Questions - 1.2
2.1 Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)C的字符串有段时间没用过了,出了几个问题。1. 在计算右边界时,需要记录s的位置,不能*s++;同时right要自减,否则
2012-04-14 22:42:42 985
原创 Top 150 Questions - 1.1
1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?这个题主要操作集中在查找上面,所以首先想到的就是哈希,时间复杂度为O(n);字符不超过256,定义256大小的数组就ok了。书上指出的其
2012-04-14 21:35:24 1064
原创 D12一些注意事项
在D12枚举时老是复位,很郁闷。看到网上经常有人出这个问题,但是没解答,经过仔细研究终于解决,这里我把可能有的问题都列出来。1.单片机的中断应设置为电平触发,中断后一定要读上次传输状态寄存器(命令40-45H),以清除中断寄存器中的中断标志。这样, PDIUSBD12的中断输出才能变回高电平,这一点非常重要。2.在接收到Setup包后,一定要调用ACK setup命令重新使能端口0。
2011-01-12 14:46:00 460
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人