//原文:
//
// Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not.
//
// FOLLOW UP
//
// Write the test cases for this method.
//
// 循环遍历整个数组,一个索引值用来指向去除后的字符串,检查每个字符,如果前面存在,就设为‘\0’,否则迁移
#include <iostream>
using namespace std;
void duplicate(char *str)
{
if (str==NULL)
{
return;
}
int size = strlen(str);
int p = 0;
for (int i = 0 ; i < size ; i++)
{
bool isExist = false;
for (int j = 0 ; j < p ; j++)
{
if (str[j] == str[i])
{
isExist = true;
}
}
if (!isExist)
{
str[p]=str[i];
p++;
}
else
str[i]='\0';
}
str[p]='\0'; }
int main()
{
char s[]="whenssssss";
duplicate(s);
cout<<s<<endl;
return 0;
}

Cracking The Coding Interview 1.3的更多相关文章

  1. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  2. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  3. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  4. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  5. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  6. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  7. 《Cracking the Coding Interview》——第13章:C和C++——题目6

    2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...

  8. 《Cracking the Coding Interview》——第5章:位操作——题目7

    2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...

  9. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  10. 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)

    #include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...

随机推荐

  1. Go语言学习之5 进阶-排序、链表、二叉树、接口

    本节主要内容: 1. 结构体和方法2. 接口 1. 结构体和方法 (1). 用来自定义复杂数据结构     (2). struct里面可以包含多个字段(属性)     (3). struct类型可以定 ...

  2. Getting Started with Processing 第二,三章总结

    第一章是文化熏陶. 第二章:开始编程 菜单栏中的 Show 的快捷键 Run:进行显示shortcut:可以通过快捷键 cmd + R 执行Present:进行全屏的显示shortcut:可以通过按下 ...

  3. computational biology | Bioinformatician | 开发者指南

    对自己的定位要明确,不要定义为码农,我是computational biologist. 入了这一行就不要三心二意,这基本注定你未来10年都在干这个,就算要转行也要先把这个做好.其实大多数人最喜欢的肯 ...

  4. java ----> 手动编译java项目

    环境: jdk1.8,cmd,notepad++ 创建java工程test,创建文件夹: src classes lib 说明: src 放置.java文件 classes 放置.class文件 li ...

  5. English trip V1 - B 4.How Do You Make a Salad? 请给我一间房? Teacher:Julia Key:imperatives 祈使句

    In this lesson you will learn to give instructions. 这节课你将将学会给出指示. 课上内容(Lesson) 词汇(Key Word ) bell pe ...

  6. (Go rails)使用Rescue_from(ActiveSupport:Rescuable::ClassMethods)来解决404(ActiveRecord::RecordNotFound)❌

    https://gorails.com/episodes/handle-404-using-rescue_from?autoplay=1 我的git: https://github.com/chent ...

  7. android-------开发常用框架汇总

    响应式编程 RxJava https://github.com/ReactiveX/RxJava RxAndroid https://github.com/ReactiveX/RxAndroid 消息 ...

  8. IDEA分享项目到GitHub出现Could not read from remote repository

    如果VCS->Import into Version Control->Share Project on GitHub出现如下错误:: 重点在最后一行Could not read from ...

  9. Django中模型层中ORM的单表操作

    ORM概念: MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发人员 ...

  10. Python安装第三方库,报错超时: Read timed out.

    1.安装beautifulsoup4 >pip install beautifulsoup4 报错超时: Read timed out. 2.解决办法:pip --default-timeout ...