zoukankan      html  css  js  c++  java
  • leetcode_youtube

    /*single number*/
    /*
        input[2,2,1]  [4,1,2,1,2]
        output:1 4
    */
    
    // i -> 2    j-> 2 2 1        ->2
    // i -> 2    j-> 2 2 1        ->2
    // i -> 1    j-> 2 2 1        ->1
    #if 0
    int search_single_number(int * num,const int numsize)
    {
        int i,j;
        for(i = 0;i < numsize;++i)
        {
            int count = 0;
            for(j = 0;j < numsize;++j)
            {
                if(num[j] == num[i])
                count ++;
            }
            if(count == 1)
                return num[i];
        }
        return;
    }
    #endif
    /*
        按位异或
        A^A = 0;
        A^0 = A;
        A^B = B^A;    
    */
    #if 1
    int search_single_number(int * num,const int numsize)
    {
        int i ;
        int n = num[0];
        for(i = 1;i < numsize;++i)
        {
            n = n ^ num[i];
        }
        return n;
    }
    #endif
    #include<stdio.h>
    #include<stdlib.h>
    void main(void)
    {
        //int num[3] = {2,2,1};
        int num[5] = {4,1,2,1,2};
        int target = search_single_number(num,sizeof(num) / sizeof(num[0]));
        printf("target = %d
    ",target);
        return ;
    }

     

  • 相关阅读:
    1050. String Subtraction
    1041. Be Unique
    1033. 旧键盘打字
    1029. 旧键盘
    1080. Graduate Admission
    1083. List Grades
    1075. PAT Judge
    sed指令进阶操作
    Mysql最大连接数
    javascript自写工具方法
  • 原文地址:https://www.cnblogs.com/anitaguangzi/p/14125237.html
Copyright © 2011-2022 走看看