摘要:
题目:删除字符串中的数字并压缩字符串。举例:输入字符串"abc123de4fg56", 输出"abcdefg"。要求:不开辟新空间,时间复杂度为O(n)。答:#include "stdafx.h"#include <iostream>using namespace std;//删除字符串中的数字并压缩字符串void RemoveNumberChar(char *str){ if (NULL == str) { return; } char *p = str; char *pNewStr = str; while (*p ! 阅读全文
摘要:
题目:给定链表的头指针和一个结点指针,在O(1)时间内删除该结点,链表结点的定义如下:struct ListNode{ int m_nKey; ListNode* m_pNext;};函数的声明如下:void DeleteNode(ListNode *pListHead, ListNode *pToBeDeleted);答:#include "stdafx.h"#include <iostream>#include <fstream>#include <ctime>using namespace std;struct ListNode{ 阅读全文
摘要:
题目:输入两个字符串,从第一个字符串中删除第二个字符串中所有的字符。举例:输入"They are students."和"aeiou",则输出之后的第一个字符串变成"Thy r stdnts."。答:#include "stdafx.h"#include <iostream>using namespace std;//在字符串中删除特定的字符void DeleteSpecialChar(char *pStr, const char *pDelStr){ const int length = 256; i 阅读全文