mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										26
									
								
								24/11/3226.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								24/11/3226.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
 | 
			
		||||
int minChanges(int n, int k)
 | 
			
		||||
{
 | 
			
		||||
    if(n<k){
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    while (n || k == 0)
 | 
			
		||||
    {
 | 
			
		||||
        if ((n & 1) < (k & 1))
 | 
			
		||||
        {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        if ((n & 1) > (k & 1))
 | 
			
		||||
        {
 | 
			
		||||
            count++;
 | 
			
		||||
        }
 | 
			
		||||
        n >>= 1;
 | 
			
		||||
        k >>= 1;
 | 
			
		||||
    }
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int minChanges1(int n, int k) {
 | 
			
		||||
        return (n & k) == k ? __builtin_popcount(n ^ k) : -1;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user