careercup
scgillian
这个作者很懒,什么都没留下…
展开
-
careercup top 150判断字符串中字符是否唯一(字符不重复)
Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures选自careercup top 150 questions 1.1#include#includeusing namespac原创 2013-04-12 19:17:59 · 932 阅读 · 0 评论 -
careercup1.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.写一个算法加入M*N矩阵中有一个元素为0,那么该元素对应的行和列的所有元素均设为0分析:如果直接循环二维数组,当该数组元素为0时,把对应的行和列的元素均设为0.这样有可能会遇到原创 2013-04-22 21:15:39 · 648 阅读 · 0 评论 -
carrercup9.3
Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log n) algorithm that finds an element in the array. You may assume that the array was originally sorted原创 2013-04-16 21:58:14 · 587 阅读 · 0 评论 -
carrercup 2.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 pointer points t原创 2013-04-25 19:27:27 · 937 阅读 · 0 评论 -
careercup2.4
careercup2.4You 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原创 2013-04-27 21:17:09 · 590 阅读 · 0 评论 -
careercup3.5用两个栈实现一个队列
3.5 Implement a MyQueue class which implements a queue using two stacks.分析Queue:first in first outstack:first in last out由于队列移除元素移除的是队尾元素,因此用栈s2保持队尾元素。两个栈栈s1中:最新的元素在最上面栈s2中:最旧的元素在最原创 2013-04-19 21:28:49 · 581 阅读 · 0 评论 -
careercup5.1
You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at原创 2013-05-02 15:10:11 · 657 阅读 · 0 评论 -
careercup8.4写出字符串的所有排列
8.4Write a method to compute all permutations of a string这题有需要注意的点在:这个字符串中可能有重复字符,因此需剔除重复排列用的递归的思想,首先第一次可以选择字符串中的任意一个字符,剔除重复的,char_set用于保存当前位可能出现的字符。flag用于控制是否出现重复字符循环中这一句prev_str=prev_str原创 2013-04-12 21:24:23 · 706 阅读 · 0 评论 -
careercup5.5求解转换两数所需修改的位数
Write a function to determine the number of bits required to convert integer A to integer B.Input: 31, 14Output: 2首先利用xor异或运算算出两数不同的位数,假设输入的两数为a,b,X=a^b,X中含有的1的位数即为要求的值为了求出X中1的位数,可以每次把X与原创 2013-05-10 15:16:49 · 659 阅读 · 0 评论