串练习--------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));

反思

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

相关推荐
澈2076 小时前
深入浅出C++滑动窗口算法:原理、实现与实战应用详解
数据结构·c++·算法
A.A呐6 小时前
【C++第二十九章】IO流
开发语言·c++
ambition202426 小时前
从暴力搜索到理论最优:一道任务调度问题的完整算法演进历程
c语言·数据结构·c++·算法·贪心算法·深度优先
代码旅人ing7 小时前
链表算法刷题指南
数据结构·算法·链表
kebeiovo7 小时前
atomic原子操作实现无锁队列
服务器·c++
Yungoal7 小时前
常见 时间复杂度计算
c++·算法
6Hzlia7 小时前
【Hot 100 刷题计划】 LeetCode 48. 旋转图像 | C++ 矩阵变换题解
c++·leetcode·矩阵
不爱吃炸鸡柳8 小时前
单链表专题(完整代码版)
数据结构·算法·链表
Ricky_Theseus8 小时前
C++右值引用
java·开发语言·c++
吴梓穆8 小时前
UE5 c++ 常用方法
java·c++·ue5