67. Add Binary




class Solution {
public:
    string addBinary(string a, string b) {
        string ans="",res="";
        int n=a.size();
        int m=b.size();
        if(!n||!m)
            return ans;
        
        int i,j;
        int cnt=0;
        for(i=n-1,j=m-1;i>=0||j>=0;i--,j--)
        {
            int tmp=cnt;
            if(i>=0)
                tmp+=a[i]-'0';
            if(j>=0)
                tmp+=b[j]-'0';
            ans=to_string(tmp%2)+ans;
            cnt=tmp/2;
        }
        if(cnt)
            ans=to_string(cnt)+ans;
        return ans;
    }
};


在 Git 中,可以通过配置 `.gitattributes` 文件来指定特定文件类型为二进制文件。此方法确保 Git 在处理这些文件时将其视为二进制数据,避免进行不必要的文本转换或差异计算。 ### 配置步骤 1. **创建或编辑 `.gitattributes` 文件** 在项目的根目录下创建一个名为 `.gitattributes` 的文件(如果尚未存在),并添加以下内容: ```plaintext *.pdf binary *.png binary ``` 上述规则告诉 Git 将所有 `.pdf` 和 `.png` 文件视为二进制文件,防止 Git 对它们进行行结束符转换(如 LF/CRLF)或生成文本差异[^1]。 2. **将 `.gitattributes` 文件提交到仓库** 确保该文件被提交到版本控制中,以便其他开发者也能够继承这一配置。 ```bash git add .gitattributes git commit -m "Configure .pdf and .png files as binary" ``` 3. **可选:全局配置属性文件** 如果希望在所有本地 Git 仓库中使用相同的 `.gitattributes` 行为,可以设置 `core.attributesFile` 指向一个全局的 `.gitattributes` 文件。 ```bash git config --global core.attributesFile ~/.gitattributes.global ``` 然后,在用户主目录下创建 `~/.gitattributes.global` 文件,并添加相同的规则内容: ```plaintext *.pdf binary *.png binary ``` 这样,所有未覆盖此设置的新仓库都会应用这些全局属性。 --- ### 示例 `.gitattributes` 内容扩展 除了基本的二进制标记外,还可以定义更复杂的规则,例如: ```plaintext # Treat all PDFs and PNGs as binary *.pdf binary *.png binary # Disable diff for specific binary types *.jpg -diff *.gif -diff ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值