mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										29
									
								
								else/DivConvert.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								else/DivConvert.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/10/2.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef LEECODE_C_DIVCONVERT_H
 | 
			
		||||
#define LEECODE_C_DIVCONVERT_H
 | 
			
		||||
 | 
			
		||||
#include <stack>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
string decimalToBinaryUsingEuclidean(int target) {
 | 
			
		||||
    stack<int> s;
 | 
			
		||||
    string result = "";
 | 
			
		||||
    while (target) {
 | 
			
		||||
        s.push(target % 2);
 | 
			
		||||
        target /= 2;
 | 
			
		||||
    }
 | 
			
		||||
    while (!s.empty()) {
 | 
			
		||||
        result.append(to_string(s.top()));
 | 
			
		||||
        s.pop();
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// test : cout << decimalToBinaryUsingEuclidean(555) << endl;
 | 
			
		||||
 | 
			
		||||
#endif //LEECODE_C_DIVCONVERT_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user