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

反思

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

相关推荐
良木生香8 分钟前
【C++初阶】STL——Vector从入门到应用完全指南(1)
开发语言·c++·神经网络·算法·计算机视觉·自然语言处理·数据挖掘
Brilliantwxx8 分钟前
【C++】String的模拟实现(代码实现与坑点讲解)
开发语言·c++·笔记·算法
楼田莉子21 分钟前
仿Muduo的高并发服务器:Channel模块与Poller模块
linux·服务器·c++·学习·设计模式
zhouwy11322 分钟前
Linux网络编程从入门到精通
linux·c++
迷途之人不知返22 分钟前
deque的简单认识
数据结构·c++
上弦月-编程24 分钟前
指针编程:高效内存管理核心
java·数据结构·算法
xieliyu.26 分钟前
Java手搓数据结构:栈与队列模拟实现
java·数据结构·学习
人道领域33 分钟前
【数据结构与算法分析】二叉树面试通关手册:遍历图解 · 分类对比 · 代码模板
数据结构·算法·leetcode·深度优先
zhouwy11334 分钟前
C++ STL标准模板库详解
c++
.54840 分钟前
Two Pointers(双指针)
java·数据结构·算法