请实现一个函数,把字符串 s
中的每个空格替换成"%20"。
class Solution {
public:
string replaceSpace(string s) {
string ans = "";
for(int i=0;i<s.size();i++)
{
if(s[i]==‘ ‘) ans+="%20";
else ans+=s[i];
}
return ans;
}
};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> vec;
while(head){
vec.push_back(head->val);
head = head->next;
}
reverse(vec.begin(),vec.end());
return vec;
}
};
原文:https://www.cnblogs.com/xuwanwei/p/14279104.html