*博客头图：

RGB颜色，例如：#AFAFAF

Hover：

RGB颜色，例如：#AFAFAF

RGB颜色，例如：#AFAFAF

孙佰贵的专栏

• 博客(66)
• 资源 (28)

转载 Turn off the rightmost set bit

reference: http://www.geeksforgeeks.org/turn-off-the-rightmost-set-bit/Problem Definition:Write a C function that unsets the rightmost set bit of an integer.Solution:Let the in

2013-06-10 09:32:51 803

转载 Multiply a given Integer with 3.5

reference: http://www.geeksforgeeks.org/multiply-an-integer-with-3-5/Problem Definition:Given a integer x, write a function that multiplies x with 3.5 and returns the integer result. Y

2013-06-10 09:32:45 774

转载 Add 1 to a given number

reference: http://www.geeksforgeeks.org/add-1-to-a-given-number/Problem Definition:Write a program to add one to a given number. You are not allowed to use operators like ‘+’, ‘-’, ‘*’

2013-06-10 09:32:41 816

转载 Next higher number with same number of set bits

reference: http://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/Problem Definition:Given a number x, find next number with same number of 1 bits in it’s binary

2013-06-10 09:32:36 963

转载 A Boolean Array Puzzle

reference: http://www.geeksforgeeks.org/a-boolean-array-puzzle/Problem Definition:Input: A array arr[] of two elements having value 0 and 1Output: Make both elements 0.Specific

2013-06-10 09:32:31 770

转载 Smallest of three integers without comparison operators

reference: http://www.geeksforgeeks.org/smallest-of-three-integers-without-comparison-operators/Problem Definition:Write a C program to find the smallest of three integers, without usi

2013-06-10 09:32:27 762

转载 Add two numbers without using arithmetic operators

reference: http://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/Problem Definition:Write a function Add() that returns sum of two integers. The function should

2013-06-10 09:32:22 857

转载 Swap bits in a given number

reference: http://www.geeksforgeeks.org/swap-bits-in-a-given-number/Problem Definition:Given a number x and two positions (from right side) in binary representation of x, write a functio

2013-06-10 09:32:18 866

转载 Count total set bits in all numbers from 1 to n

reference: http://www.geeksforgeeks.org/count-total-set-bits-in-all-numbers-from-1-to-n/Problem Definition:Given a positive integer n, count the total number of set bits in binary repr

2013-06-10 09:31:56 1382

转载 Find the element that appears once

reference: http://www.geeksforgeeks.org/find-the-element-that-appears-once/Problem Definition:Given an array where every element occurs three times, except one element which occurs onl

2013-06-10 09:31:52 771

转载 Count set bits in an integer

reference: http://www.geeksforgeeks.org/count-set-bits-in-an-integer/Problem Definition:Write an efficient program to count number of 1s in binary representation of an integer.So

2013-06-09 14:12:39 982

转载 Write an Efficient C Program to Reverse Bits of a Number

reference: http://www.geeksforgeeks.org/write-an-efficient-c-program-to-reverse-bits-of-a-number/Problem Definition:Write an Efficient C Program to Reverse Bits of a NumberSolu

2013-06-09 14:12:35 993

转载 Check for Integer Overflow

reference: http://www.geeksforgeeks.org/check-for-integer-overflow/Problem Definition:Write a “C” function, int addOvf(int* result, int a, int b) If there is no overflow, the function pl

2013-06-09 14:12:30 1095

转载 Find the Number Occurring Odd Number of Times

reference: http://www.geeksforgeeks.org/find-the-number-occurring-odd-number-of-times/Problem Definition:Given an array of positive integers. All numbers occur even number of times excep

2013-06-09 14:12:26 912

转载 Find the two non-repeating elements in an array of repeating elements

reference: http://www.geeksforgeeks.org/find-two-non-repeating-elements-in-an-array-of-repeating-elements/Problem Definition:Given an array in which all numbers except two are repeated o

2013-06-09 14:12:20 1025

转载 Rotate bits of a number

reference: http://www.geeksforgeeks.org/rotate-bits-of-an-integer/Problem Definition:Bit Rotation: A rotation (or circular shift) is an operation similar to shift except that the bits

2013-06-09 14:12:16 869

转载 Compute the minimum or maximum of two integers without branching

reference: http://www.geeksforgeeks.org/compute-the-minimum-or-maximum-max-of-two-integers-without-branching/Problem Definition:The key idea is to incorporate the branch into one equation.

2013-06-09 14:12:13 763

转载 Compute modulus division by a power-of-2-number

reference: http://www.geeksforgeeks.org/compute-modulus-division-by-a-power-of-2-number/Problem Definition:Compute n modulo d without division(/) and modulo(%) operators, where d is a

2013-06-09 14:12:09 738

转载 Compute the integer absolute value (abs) without branching

reference: http://www.geeksforgeeks.org/compute-the-integer-absolute-value-abs-without-branching/Problem Definition:Compute the integer absolute value (abs) without branching.Solut

2013-06-09 14:12:04 1348

转载 Find whether a given number is a power of 4 or not

reference: http://www.geeksforgeeks.org/find-whether-a-given-number-is-a-power-of-4-or-not/Problem Definition:Find whether a given number is a power of 4 or not.Solution:

2013-06-09 14:12:00 844

转载 Swap all odd and even bits

reference: http://www.geeksforgeeks.org/swap-all-odd-and-even-bits/Problem Definition:Given an unsigned integer, swap all odd bits with even bits. For example, if the given number is 23 (000

2013-06-09 14:11:40 1313

转载 Binary representation of a given number

reference: http://www.geeksforgeeks.org/binary-representation-of-a-given-number/Problem Definition:Write a program to print Binary representation of a given number.Solution:Thi

2013-06-09 14:11:36 1183

转载 Position of rightmost set bit

reference: http://www.geeksforgeeks.org/position-of-rightmost-set-bit/Problem Definition:Write a one line C function to return position of first 1 from right to left, in binary representat

2013-06-09 14:11:32 764

转载 Write one line C function to find whether a no is power of two

reference: http://www.geeksforgeeks.org/write-one-line-c-function-to-find-whether-a-no-is-power-of-two/Problem Definition:Write one line C function to find whether a no is power of two.

2013-06-09 14:11:28 780

转载 Efficient way to multiply with 7

reference: http://www.geeksforgeeks.org/efficient-way-to-multiply-with-7/Problem Definition:Figure out a way to multiply with 7 efficiently.Solution:We can multiply a number by

2013-06-09 14:11:24 706

转载 Write a C program to find the parity of an unsigned integer

reference: http://www.geeksforgeeks.org/write-a-c-program-to-find-the-parity-of-an-unsigned-integer/Problem Definition:Parity: Parity of a number refers to whether it contains an odd or

2013-06-09 14:11:19 874

转载 Write an Efficient Method to Check if a Number is Multiple of 3

reference: http://www.geeksforgeeks.org/write-an-efficient-method-to-check-if-a-number-is-multiple-of-3/Problem Definition:The very first solution that comes to our mind is the one tha

2013-06-09 14:11:12 991

转载 Next Power of 2

reference: http://www.geeksforgeeks.org/next-power-of-2/Problem Definition:Write a function that, for a given no n, finds a number p which is greater than or equal to n and is a power of

2013-06-09 14:11:06 1929

转载 Count number of bits to be flipped to convert A to B

reference: http://www.geeksforgeeks.org/count-number-of-bits-to-be-flipped-to-convert-a-to-b/Problem Definition:You are given two numbers A and B. Write a program to count number of bits

2013-06-09 14:10:12 747

原创 Bit manipulation

When should you use bitwise operators?Bitwise operators are used forsaving more space orsaving some time. There are also times when you need to use bitwise operators: if you're working with co

2013-06-03 11:42:00 2996 2

原创 [LeetCode]ZigZag Conversion

class Solution {//be careful with the special case//when done with coding, figure out some cases (including illegal, normal, edge cases)//to run with this solution, this will help to get a bug-free

2013-06-03 09:09:50 958

原创 [LeetCode]Word Search

int Dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};class Solution {//DFS Find the pathpublic: void DFS(int curX, int curY, int curPos, vector>& visit, bool& OK, vector> &board, string& word ) { if(

2013-06-03 09:09:41 3369

class Solution { //Split the problem in three steps: // //1.build the adjacency list //2.do a BFS to get a vector> prev array. For example, prev[1] = [2, 3, 0] means we can go from (2 to 1) or (3

2013-06-03 09:09:29 2178

class Solution {public: int ladderLength(string start, string end, unordered_set &dict) { // Start typing your C/C++ solution below // DO NOT write int main() function //BFS(because all edge i

2013-06-03 09:09:11 1219

原创 [LeetCode]Wildcard Matching

class Solution {//1. No match. Simply return false. This is the last case in the program.//2. Single match. Either *s == *p, or *p == '?'. The return value of this case depends on the //result of t

2013-06-03 09:09:05 2171

原创 [LeetCode]Validate Binary Search Tree

struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {//hint: when involved with BST, always remember that special e

2013-06-03 09:09:00 1400 1

原创 [LeetCode]Valid Sudoku

class Solution {public: bool isValidSudoku(vector > &board) { // Start typing your C/C++ solution below // DO NOT write int main() function return CheckBlock(board) && CheckStrip(board); } b

2013-06-03 09:08:55 2292

原创 [LeetCode]Valid Parentheses

class Solution {//stackpublic: bool isValid(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function stack charStack; for (int i = 0; i < s.size(); ++i) {

2013-06-03 09:08:48 831

原创 [LeetCode]Valid Palindrome

class Solution {public: bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function TransmitString(s); for (int i = 0, j = s.size()-1; i <= j;

2013-06-03 09:08:42 2533

原创 [LeetCode]Valid Number

class Solution {//finite state machine//status 1 => 小数点前面的部分//status 2 => 小数点后到'e'前面的部分//status 3 => e后面的科学计数法部分//should practice couple times morepublic: bool isNumber(const char *s) { // St

2013-06-03 09:08:28 2122 2

2011-12-06

2011-04-02

2011-04-02

2010-05-11

2010-04-19

2009-08-20

2009-08-04

2009-08-04

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-09

2009-03-09

链表C语言实现 功能齐全

/* head 为链表的头指针，也就是第一个节点的地址，只有在加入第一个节点的时候有用 last 是这样一个节点，当你输入数据的时候，内存首先开辟一个区域，此时，last指向上一个节点的地址 curPosi 永远指向当前新开辟的区域，一旦指向当前新开辟的区域，那么curPosi 就和以前的所有节点没有关系了 为了让last永远指向上一个节点，在给last的 next指针赋值之后，last要指向当前节点 */

2009-03-09