摘要:
分析:对于x和y1.首先计算各位相加但不计进位;2.记下进位;3.把前步的结果相加。 1 int add(int num1, int num2) 2 { 3 int sum, carry; 4 do 5 { 6 sum = num1^num2; 7 carry = (nu... 阅读全文
摘要:
解法一:把构造函数设为私有 将构造函数定义为私有,然后通过定义公有的静态函数来创建和释放类的实例。 1 class SealedClass 1 2 { 3 public: 4 static SealedClass1* GetInstance() 5 { 6 ret... 阅读全文
摘要:
Description:Reverse a singly linked list.Code: 1 ListNode* reverseList(ListNode* head) { 2 ListNode* preNode = NULL; 3 ListNode* p = head; 4 ... 阅读全文
摘要:
Description:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --... 阅读全文
摘要:
Description:Given a range [m, n] where 0 =0; i++)15 x = x&i;16 return x;17 }18 }View Code 阅读全文
摘要:
Description:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecti... 阅读全文
摘要:
Description:Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to botto... 阅读全文
摘要:
Description:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint... 阅读全文
摘要:
变换一个整数的符号,即正数变负数,负数变正数。1 int reverseSign(int n) {2 return ~n+1;3 } 阅读全文
摘要:
给出一个16位的无符号整数。称这个二进制数的前8位为“高位”,后8位为“低位”。现在写一程序将它的高低位交换。例如,数34520用二进制表示为:1000011011011000将它的高低位进行交换,我们得到了一个新的二进制数:1101100010000110它即是十进制的55430。这个问题用位操作... 阅读全文
摘要:
Description:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110100111... 阅读全文