leetcode476

时间:2023-03-09 08:10:34
leetcode476
    public class Solution
{
public int FindComplement(int num)
{
//计算数字二进制的反码
var list = new List<int>(); do
{
var n = num % ;
list.Add(n);
num /= ;
}
while (num != ); var length = list.Count;
for (int i = ; i < length; i++)
{
if (list[i] == )
{
list[i] = ;
}
else
{
list[i] = ;
}
} int result = ; for (int i = ; i < length; i++)
{
result += list[i] * Convert.ToInt32(Math.Pow(, i));
} //Console.WriteLine(result); return result;
}
}

https://leetcode.com/problems/number-complement/#/description