Cracking the coding interview
文章平均质量分 77
hillchan31
这个作者很懒,什么都没留下…
展开
-
cci-Q1.1 判断字符串中字符是否唯一
原文:Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?译文:实现一个算法来判断一个字符串中的字符是否唯一(即没有重复).不能使用额外的数据结构。 (即只使用基本的数据结构)原创 2013-07-08 17:07:10 · 1171 阅读 · 0 评论 -
cci-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.译文:实现一个栈,除了原创 2013-07-30 16:53:34 · 1111 阅读 · 0 评论 -
cci-Q2.5 寻找环形链表的起点
原文:Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) linked list in which a node’s next point原创 2013-07-22 18:09:33 · 741 阅读 · 0 评论 -
cci-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. Write a f原创 2013-07-19 16:04:38 · 598 阅读 · 0 评论 -
cci-Q2.3 只给出中间节点,删除链表中间节点
原文:Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.EXAMPLEInput: the node ‘c’ from the linked list a->b->c->d->e Result: nothi原创 2013-07-12 15:32:36 · 729 阅读 · 0 评论 -
cci-Q2.2 链表倒数第n节点值
原文:Implement an algorithm to find the nth to last element of a singly linked list.译文:实现一个算法从一个单链表中返回倒数第n个元素。使用两个指针,first和second,当second.next==null时,first为倒数第(second-first)个节点 pub原创 2013-07-12 11:14:56 · 953 阅读 · 0 评论 -
cci-Q2.1 未排序链表去重
原文:Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?译文:从一个未排序的链表中移除重复的项进一步地,如果不允许原创 2013-07-10 17:59:21 · 1970 阅读 · 0 评论 -
cci-Q1.5 空格替换为%20
原文:Write a method to replace all spaces in a string with ‘%20’.译文:写一个函数,把字符串中所有的空格替换为%20 。将字符串转为字符数组;变量数组找到空格的个数;申请一个新的字符数组,长度为len+2×count public static String replaceSpace(String原创 2013-07-09 15:30:39 · 632 阅读 · 0 评论 -
cci-Q1.6 矩形90度旋转
原文: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?译文:一张图像表示成NxN的矩阵,图像中每个像原创 2013-07-09 17:07:44 · 655 阅读 · 0 评论 -
cci-Q1.4 判断两个字符串是否为变位词
原文:Write a method to decide if two strings are anagrams or not.译文:写一个函数判断两个字符串是否是变位词。An anagram is a type of word play, the result of rearranging the letters of a word or phrase to pro原创 2013-07-09 15:01:57 · 941 阅读 · 0 评论 -
cci-Q1.8 调用一次子字符串判断确认s2是否为s1的旋转字符
原文: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 isSub原创 2013-07-10 12:18:54 · 826 阅读 · 0 评论 -
cci-Q1.7 二维数组置0
原文: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,因为在遍历的过程中可能遇到之前被置0的元原创 2013-07-10 11:16:02 · 1566 阅读 · 0 评论 -
cci-Q1.2 C风格字符串反转
原文:Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)译文:写代码翻转一个C风格的字符串。(C风格的意思是"abcd"需要用5个字符来表示,包含末尾的 结束字原创 2013-07-08 18:28:13 · 694 阅读 · 0 评论 -
cci-Q3.1 一个数组实现三个栈
原文:Describe how you could use a single array to implement three stacks.译文:你如何只用一个数组实现三个栈?根据栈的大小,申请一个3*stacksize的数组。public class stack3 { int[] buffer = null; int size = 0;原创 2013-07-24 14:05:13 · 582 阅读 · 0 评论