当前位置:网站首页>LeetCode-1528-重新排列字符串-哈希表-字符串
LeetCode-1528-重新排列字符串-哈希表-字符串
2022-06-25 22:01:00 【李烦烦搞快点】
Note:
开个哈希表记录下每个数字对应的字母,然后从0开始把字符串复原出来即可,O(N)复杂度
代码如下:
class Solution {
public:
string restoreString(string s, vector<int>& indices) {
unordered_map<int, char> hash;
string ans;
for(int i = 0; i < indices.size(); i ++)
hash[indices[i]] = s[i];
for(int i = 0; i < indices.size(); i ++)
ans += hash[i];
return ans;
}
};
边栏推荐
- QLabel 文字水平滚动显示
- [modulebuilder] GP service realizes the intersection selection of two layers in SDE
- [untitled] open an item connection. If it cannot be displayed normally, Ping the IP address
- 关于go中资源泄漏/goroutine泄漏/内存泄漏/CPU打满等情况分析
- pdm的皮毛
- [opencv450 samples] read the image path list and maintain the proportional display
- 【ModuleBuilder】GP服务实现SDE中两个图层相交选取
- PDM fur
- Determine whether the appointment time has expired
- 字符串
猜你喜欢
随机推荐
Basic operator
【opencv450-samples】inpaint 使用区域邻域恢复图像中的选定区域
Rk3568+ Hongmeng industrial control board industrial gateway video gateway solution
[untitled] open an item connection. If it cannot be displayed normally, Ping the IP address
剑指 Offer 46. 把数字翻译成字符串(DP)
小程序-视图与逻辑
cookie、session、token
Set up your own website (15)
Transformers load pre training model
电路模块分析练习6(开关)
Leetcode(435)——无重叠区间
App new function launch
问题记录与思考
[opencv450 samples] read the image path list and maintain the proportional display
What is Unified Extensible Firmware Interface (UEFI)?
Xinchida nd04 nd04c nrf52832 (52810) ble module (low power Bluetooth communication module) at command test
[Axi] interpretation of Axi protocol atomic access
电路模块分析练习5(电源)
对卡巴斯基发现的一个将shellcode写入evenlog的植入物的复现
Ble Low Power Bluetooth networking process and Bluetooth role introduction








