//原文:
//
// 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. pseudotime专题

    review:Computational Methods for Trajectory Inference from Single-Cell Transcriptomics Tools/Algorit ...

  2. 学习Py——自己模拟写的一个Range功能

    #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" # function: Modeled range ...

  3. drf 认证、权限、限流、过滤、排序、分页器

    认证Authentication 准备工作:(需要结合权限用) 1. 需要使用到登陆功能,所以我们使用django内置admin站点并创建一个管理员. python manage.py creates ...

  4. 树上第k大联通块

    题意:求树上第k大联通块 n,k<=1e5 考虑转化为k短路的形式. 也就是要建出一张图是的这条图上每一条S到T的路径都能代表一个联通块. 点分治建图 递归下去,假定每个子树的所有联通块中都可以 ...

  5. TCP/UDP协议简要梳理

    TCP/UDP协议简要梳理 TCP TCP,Transmission Control Protocol,传输控制协议是一种面向连接的.可靠的.基于字节流的传输层通信协议.在因特网协议族中,TCP所在的 ...

  6. 自动化(脚本)安装httpd服务

    思路: 1.检查传递的参数,httpd源码文件 2.检查执行脚本的用户是否为root 3.检查rpm是否安装过httpd,若安装过,则卸载 4.安装编译所需的工具 5.从网上下载httpd源码 6.配 ...

  7. DFS CCPC2017 南宁I题

    The designers have come up with a new simple game called “Rake It In”. Two players, Alice and Bob, i ...

  8. 廖雪峰网站:学习python函数—调用函数(一)

    # 调用函数 # 可以直接从Python的官方网站查看文档: # http://docs.python.org/3/library/functions.html#abs n = abs(100) # ...

  9. shiro中INI配置

    4.1 根对象SecurityManager 从之前的Shiro架构图可以看出,Shiro是从根对象SecurityManager进行身份验证和授权的:也就是所有操作都是自它开始的,这个对象是线程安全 ...

  10. python-day79--知识回顾

    内容回顾: 1. 可迭代对象.迭代器.生成器是什么?什么区别? 可迭代对象,含有__iter__,返回一个迭代器 迭代器,含有__iter__,__next__方法 生成器,yield,__next_ ...