題目描述:Given an array of n integers, such that each number in the array appears exactly twice, except for three numbers (say a, b and c) which appear exactly once.In O(n) time and O(1) space find a,b and c.
題目描述:求給定整數其二進位形式含1的個數,比如255含8個1,因其二進位表示為11111111;下面給出了兩種求解代碼實現。#include <iostream>using namespace std;int CountOne( int n){ int count = 0 ; while (n) { ++ count; n &= n - 1 ; } return count;} int
題目描述:如式的輸出矩陣。代碼如下:#include <cstdio>void MatrixSpiralOutput(int n){ int **matrix = new int*[n](); for (int idx = 0; idx < n; idx++) { matrix[idx] = new int[n](); } int row = 0, col = 0; int i = 0; int len = n * n;
題目1描述:you are given an array of integers containing only 0s and 1s. you have to place all the 0s in even position and 1s in odd position and if suppose no if 0s exceed no. of 1s or vice versa then keep them untouched. Do that in ONE PASS and WITHOUT
題目描述:Let A and B are sorted array with length m and n respectively, given k, the problem is to find the first k smallest elements which are composed of A[i]+B[j]. e.g. A={1,3,5,7}, B={2,6, 10}, k = 3 Output: 1+2 3+2 1+6
題目描述:You have a read-only array A[1..n] which is populated by numbers from 1..n-1, which implies atleast one repetition. However, there can be more. Find any one repeated number in linear time O(n) using constant space.