串练习--------535.TinyURL的加密和解密

题目:点这里

代码

cpp 复制代码
class Solution {
public:

    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
        for(int i=0;i<longUrl.size();i++){
            longUrl[i]^=12;
        }
        return longUrl;
    }

    // Decodes a shortened URL to its original URL.
    string decode(string shortUrl) {
        for(int i=0;i<shortUrl.size();i++){
            shortUrl[i]^=12;
        }
    }
};

// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));

反思

异或'^'可以对地址进行加密操作。

相关推荐
ShineWinsu6 小时前
对于C++:auto_ptr、unique_ptr、shared_ptr的模拟实现
c++·面试·笔试·智能指针·unique_ptr·shared_ptr·auto_ptr
XLYcmy8 小时前
京东 算法实习一面 下+手撕
c++·python·llm·概率论·数据处理·训练·codebert
反转180度8 小时前
Qt 6 + C++17 实现 SFTP 批量部署:工业设备运维工具实战解析
运维·c++·qt
码匠许师傅10 小时前
【C++ 面试真题】聊聊 C++ 的多继承与虚继承
开发语言·c++·面试
有点。11 小时前
C++认识数
开发语言·c++
Herbert_hwt11 小时前
C语言零基础入门:循环控制与数据类型详解
c语言·数据结构·算法
2023自学中12 小时前
Qt 简易聊天室(第二篇),单线程 改为 多线程,方便后续增加文件传输功能
c++·qt
晚风醉蝶13 小时前
1-6-插入排序-InsertionSort
java·数据结构·排序算法
Tyler_TXZ13 小时前
C++C语言之——二叉树
c语言·开发语言·数据结构·c++·二叉树
有点。13 小时前
C++二叉树二(练习题)
数据结构·c++·算法·图论