
google面试-CTCI
文章平均质量分 65
JJDiaries
JJ diaries-still-always-forever
展开
-
[google面试CTCI] 1-1.判断一个字符串是否包含重复字符
【字符串与数组】Q:Implement an algorithm to determine if a string has all unique characters What if you can not use additional data structures?题目:实现一个算法来判断一个字符串是否包含重复字符。如果不能使用额外数据结构,怎么做?原创 2013-10-19 09:48:23 · 1261 阅读 · 0 评论 -
[google面试CTCI] 2-2 找出链表的倒数第n个节点元素
【链表】Q:Implement an algorithm to find the nth to last element of a singly linked list .题目:找出链表的倒数第n个节点元素。解答: 方法一:利用两个指针p,q,首先将q往链表尾部移动n位,然后再将p、q一起往后移,那么当q达到链表尾部时,p即指向链表的倒数第n个节点。node* f原创 2013-10-20 09:24:43 · 1455 阅读 · 0 评论 -
2-5 求有环链表的环入口节点(证明及代码)
【链表】Q:Given a circular linked list, implement an algorithm which returns node at the begin-ning of the loop DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next poi原创 2013-10-20 11:07:01 · 2185 阅读 · 0 评论 -
[google面试CTCI] 2-3 只给定链表中间节点指针,如何删除中间节点?
【链表】Q:Implement an algorithm to delete a node in the middle of a single linked list, givenonly access to that node EXAMPLEInput: the node ‘c’ from the linked list a->b->c->d->eResult: noth原创 2013-10-20 09:26:06 · 1051 阅读 · 0 评论 -
[google面试CTCI] 2-1.移除链表中重复元素
【链表】Q: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?题目:编码实现从无序链表中移除重复项。 如果不能原创 2013-10-20 09:22:23 · 1405 阅读 · 0 评论 -
[google面试CTCI] 1-5.替换字符串中特定字符
【字符串与数组】Q:Write a method to replace all spaces in a string with ‘%20’题目:写一个算法将一个字符串中的空格替换成%20解答:很直观的解法,首先统计出字符串中空格个数,然后分配新的内存空间,依次从头到尾复制原字符串到新字符串中,遇到空格,则复制%20这三个字符。还有没有其他更好点的方法呢??char* r原创 2013-10-19 11:19:23 · 944 阅读 · 0 评论 -
[google面试CTCI] 1-4.判断两个字符串是否由相同字符组成
【字符串与数组】Q:Write a method to decide if two strings are anagrams or not题目:写一个算法来判断两个字符串是否为换位字符串。(换位字符串是指组成字符串的字符相同,但位置不同)解答: 方法一:假设为ascii2码字符串,那么可以分配两个256大小的int数组,每个数组用于统计一个字符串各个字符出现的次数,原创 2013-10-19 10:38:17 · 1264 阅读 · 0 评论 -
[google面试CTCI] 1-8.判断子字符串
【字符串与数组】Q: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 usingonly one call t原创 2013-10-19 11:27:16 · 1056 阅读 · 0 评论 -
[google面试CTCI] 1-7.将矩阵中特定行、列置0
【字符串与数组】Q:Write an algorithm such that if an element in an MxN matrix is 0, its entire row andcolumn is set to 0.题目:写一个算法,如果一个 MxN矩阵中某个元素为0,则将该元素所在的行、列都置为0.解答:方法一:错误的解法,思维误区。依次遍历二维数组(矩原创 2013-10-19 11:20:05 · 1008 阅读 · 0 评论 -
[google面试CTCI] 1-6.图像旋转问题
【字符串与数组】Q:Given an image represented by an NxN matrix, where each pixel in the image is 4bytes, write a method to rotate the image by 90 degrees Can you do this in place?题目:假定一幅图像能用NxN的矩阵表示,每个原创 2013-10-19 11:19:46 · 1309 阅读 · 0 评论 -
[google面试CTCI] 2-4 计算两个单链表所代表的数之和
【链表】Q: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原创 2013-10-20 10:06:20 · 1225 阅读 · 0 评论 -
[google面试CTCI] 2-0.链表的创建
创建链表、往链表中插入数据、删除数据等操作,以单链表为例。 1.使用C语言创建一个链表:typedefstruct nd{ int data;struct nd* next; } node;//初始化得到一个链表头节点node* init(void){node* head=(node*)malloc(sizeof(node));if(head原创 2013-10-20 09:21:23 · 861 阅读 · 0 评论 -
[google面试CTCI]1-3.字符串去重
【字符串与数组】Q:Design an algorithm and write code to remove the duplicate characters in a stringwithout using any additional buffer NOTE: One or two additional variables are fineAn extra copy of原创 2013-10-19 10:30:09 · 4858 阅读 · 0 评论 -
[google面试CTCI] 1-2 逆转c风格字符串
【字符串与数组】Q:Write code to reverse a C-Style String (C-String means that “abcd” is represented asfive characters, including the null character )题目:将一个c风格字符串逆转(c风格字符串即以空字符结尾的字符串)。原创 2013-10-19 10:14:01 · 1163 阅读 · 0 评论 -
程序员面试题集锦
谷歌面试官经典作品(CTCI)目录1.1 判断一个字符串中的字符是否唯一1.2 字符串翻转1.3 去除字符串中重复字符1.8 利用已知函数判断字符串是否为另一字符串的子串2.1 从链表中移除重复结点2.2 实现一个算法从一个单链表中返回倒数第n个元素2.3 给定链表中间某结点指针,删除链表中该结点2.4 求由两个链表结点组成的数之和原创 2015-09-06 23:23:48 · 8066 阅读 · 1 评论