Skip to content

Instantly share code, notes, and snippets.

@ZhuGuanyu
ZhuGuanyu / compressString.java
Created September 7, 2014 01:09
CareerCup 1.5 compressString
/**
* 1.5 Implement a method to perform basic string compression using the counts of repeated characters.
* For example, the string aabcccccaaa would become a2blc5a3.
* If the "compressed" string would not become smaller than the original string,
* your method should return the original string.
* Learn this code that how to add the tips and notes
* this code is very good.
*
*
@ZhuGuanyu
ZhuGuanyu / replacespace.java
Created September 6, 2014 14:26
CareerCup 1.4 Replace the Spaces
// 1.4 Write a method to replace all spaces in a string with'%20'.
// You may assume that the string has sufficient space at the end of the
// string to hold the additional characters, and that you are given the "true" length
// of the string.
// (Note: if implementing in Java, please use a character array so that you can
// perform this operation in place.)
// EXAMPLE
// Input: "Mr John Smith "
@ZhuGuanyu
ZhuGuanyu / permutation_string.java
Created June 18, 2014 18:59
CareerCup 1.3 Permutation_String
/*
Problem : 1.3 Given two strings, write a method to decide if one is a permutation of the other.
Language : JAVA
Solution: Assuming that the string only consist of ASCii letters. Because the ASCii has at most 256 letters.
So here we can simulate the hashing operation.
Record the appearing times of every character from the first string.
reduce the number of the asc array if the second string has the same character with the first string.
*/
@ZhuGuanyu
ZhuGuanyu / reverse_string.cpp
Created June 18, 2014 06:04
CareerCup 1.2 Reverse String
/*
Problem: 1.2 Implement a function void reverse(char* str) in C or C++ which reverses a null-terminated string.
// CareerCup
//
// Solution:
Step1 : caculate the length of the string.
Step2 : using an additional char space to help swap the i-th position and the (length-1-i)-th position.
// Created by Guanyu Zhu on 6/17/14.
// Copyright (c) 2014 Guanyu Zhu. All rights reserved.
@ZhuGuanyu
ZhuGuanyu / Unique_String.java
Last active August 29, 2015 14:02
CareerCup 1.1 Unique String
/*
Problem : 1.1 Implement an algorithm to determine if a string has all unique characters. Whatif you cannot use additional data structures?
Language : JAVA
Solution: Assuming that the string only consist of ASCii letters. Because the ASCii has at most 256 letters.
So here we can simulate the hashing operation.
To find out if one letter can appear twice in the string.
*/