上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 25 下一页
摘要: 19 1 Write a function to swap a number in place without temporary variablesvoid swap(int &a, int &b){ b = a - b; // 4 = 9 - 5 a = a - b; // 5 = 9 - 4 b = a + b; // 9 = 4 + 5 }void swap(int & a, int &b){ a = a^b; b = a^b; a = a^b;}19.3 Write an algorithm which computes the number of t 阅读全文
posted @ 2013-09-11 20:51 冰点猎手 阅读(253) 评论(0) 推荐(0)
摘要: 16.5Write a program to find whether a machine is big endian or little endianBig-Endian和Little-Endian的定义如下:1) Little-Endian就是低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。2) Big-Endian就是高位字节排放在内存的低地址端,低位字节排放在内存的高地址端。举一个例子,比如数字0x12 34 56 78在内存中的表示形式为:1)大端模式:低地址 -----------------> 高地址0x12 | 0x34 | 0x56 | 0x782)小... 阅读全文
posted @ 2013-09-10 23:31 冰点猎手 阅读(163) 评论(0) 推荐(0)
摘要: 13.9Write a smart pointer (smart_ptr) classtemplateclass SmartPoint{ public: SmartPoint(T *ref){ ref_ = ref; count_ = (unsigned int *)malloc(sizeof(unsigned int )); *count_ = 1; } SmartPoint(SmartPoint &sptr){ ref_ = sptr.ref_; count_ = sptr.count_; ++(*count_); } SmartPoint& operator =(Smar 阅读全文
posted @ 2013-09-10 21:15 冰点猎手 阅读(225) 评论(0) 推荐(0)
摘要: 8.1 水题8.2Imagine a robot sitting on the upper left hand corner of an NxN grid The robot canonly move in two directions: right and down How many possible paths are there forthe robot?FOLLOW UPImagine certain squares are “of limits”, such that the robot can not step on them Design an algorithm to get. 阅读全文
posted @ 2013-09-04 21:14 冰点猎手 阅读(343) 评论(0) 推荐(0)
摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()" class Solution {public: DFS(string s, int left, int ri 阅读全文
posted @ 2013-09-04 20:46 冰点猎手 阅读(156) 评论(0) 推荐(0)
摘要: 直接插入排序:稳定排序 时间复杂度 O(n2)void insertSort(int data[], int N){ if(N =0 && data[j] > temp){ data[j+1] = data[j]; --j; } if(j != i-1) data[j+1] = temp; } }View Code二分法插入排序:稳定排序 O(n2)void binSort(int data[], int N){ if(N >1 + right>>1 ; ... 阅读全文
posted @ 2013-09-03 19:42 冰点猎手 阅读(274) 评论(0) 推荐(0)
摘要: The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "321"Given n and k, return the kth permutat 阅读全文
posted @ 2013-09-02 23:26 冰点猎手 阅读(232) 评论(0) 推荐(0)
摘要: You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S: "barfoothefoobarman"L: ["foo", &q 阅读全文
posted @ 2013-09-01 16:48 冰点猎手 阅读(161) 评论(0) 推荐(0)
摘要: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 unit 阅读全文
posted @ 2013-09-01 15:34 冰点猎手 阅读(181) 评论(0) 推荐(0)
摘要: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each 阅读全文
posted @ 2013-08-29 22:50 冰点猎手 阅读(160) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 25 下一页