LeetCode Weekly Contest 171 2問目 - Minimum Flips to Make a OR b Equal to c [1318]

Source

LeetCode Weekly Contest 171
問題文

問題概要

省略

解法

省略

cLayversion 20200119-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

class Solution {
public:
  int minFlips(int a, int b, int c) {
    int x, y, z;
    int res = 0;
    rep(i,31){
      x = (a>>i) & 1;
      y = (b>>i) & 1;
      z = (c>>i) & 1;
      if(z==(x|y)) continue;
      if(z==1) res++;
      if(z==0) res += x + y;
    }
    return res;
  }
};

Current time: 2024年04月19日10時48分20秒
Last modified: 2020年01月25日23時05分00秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: