小编Sar*_*rah的帖子

如何使空间复杂度为O(1)

我试图回答以下问题:你有一个整数数组,这样每个整数都有一个奇数个时间,除了3个.找到三个数字.

到目前为止,我带来了蛮力方法:

 public static void main(String[] args) {
    // TODO Auto-generated method stub

    int number[] = { 1, 6, 4, 1, 4, 5, 8, 8, 4, 6, 8, 8, 9, 7, 9, 5, 9 };
    FindEvenOccurance findEven = new FindEvenOccurance();
    findEven.getEvenDuplicates(number);

  }

  // Brute force
  private void getEvenDuplicates(int[] number) {

    Map<Integer, Integer> map = new HashMap<Integer, Integer>();

    for (int i : number) {

      if (map.containsKey(i)) {
        // a XOR a XOR a ---- - -- - - odd times = …
Run Code Online (Sandbox Code Playgroud)

algorithm bit-manipulation time-complexity space-complexity data-structures

17
推荐指数
1
解决办法
1524
查看次数

如何在Pandas中将negative列和Nan列值都更改为Zero

我的数据框架如下:

    A    B
10  AAA  0.0333
20  BBB  -67
30  CCC -0.98
40  DDD  NaN
Run Code Online (Sandbox Code Playgroud)

如何更改B列值(仅限负值和NaN为0)

到目前为止我试过像:

df[df< 0 ] = 0 
df.fillna(0, inplace=True)
Run Code Online (Sandbox Code Playgroud)

但是在一个命令中有效吗?我是熊猫新手.请告诉我这是不是最好的方法.

python dataframe pandas

3
推荐指数
1
解决办法
3344
查看次数