• [算法]从十亿个数中找出不重复的数字


     1 import java.util.*;
     2 
     3 public class SelectOnlys {
     4     long S1 = 2 ^ 16;
     5 
     6 
     7     int whichSeg(long s) {
     8         long L = S1;
     9         int flag = 0;
    10         while (s >= L) {
    11             s %= L;
    12             flag++;
    13         }
    14         return flag;
    15     }
    16 
    17     Collection<Integer> run(long[] a) {
    18         int[] count = new int[2 ^ 16];
    19         Collection<Integer> res = new ArrayList<Integer>();
    20         for (int i = 0; i < a.length; i++) {
    21             int seg = whichSeg(a[i]);
    22             int rem = (int) (a[i] % S1);
    23 
    24             if ((count[rem] & (1 << (2 * seg))) != 1) {
    25                 count[rem] |= 1 << (2 * seg);
    26             } else if ((count[rem] & (1 << (1 + 2 * seg))) != 1) {
    27                 count[rem] |= 1 << (1 + 2 * seg);
    28             }
    29 
    30         }
    31 
    32         for (int i = 0; i < a.length; i++) {
    33             int[] b = {1, 3, 5, 7};
    34             for (int one : b) {
    35                 if ((count[i] & (1 << one)) != 1 && (count[i] & (1 << (one - 1))) == 1) {
    36                     res.add((int) (long) (one * S1 + a[i]));
    37                 }
    38             }
    39 
    40         }
    41         return res;
    42 
    43     }
    44 
    45 }
  • 相关阅读:
    常用linux命令
    console页面进去太慢优化
    CentOS7 查看最大线程连接数
    外部ssh连接Ubuntu系统
    Ubantu 防火墙管理
    oracle 闪回
    oracle用户密码过期
    base64编码原理
    Linux 备份数据库mysql
    python静态方法-类方法
  • 原文地址:https://www.cnblogs.com/fcyworld/p/7538116.html
Copyright © 2020-2023  润新知