Skip to content

Instantly share code, notes, and snippets.

@goctave
goctave / 1.c
Created April 16, 2012 03:10
CareerCup 1.1
/**************************************************
1.最简单的方法就是两层循环,复杂度O(n^2)
2.使用排序,然后找重复。复杂度为O(nlgn)+O(n)=O(nlgn)
3.直接使用快排,在排序过程中,如果发现有重复的,立即结束递归
****************************************************/
#include <stdio.h>
#include <string.h>
int repeat;
@goctave
goctave / 2.c
Created April 17, 2012 02:09
CareerCup 1.2
#include <stdio.h>
#include <string.h>
void exchange(char str[])
{
int len = strlen(str);
char *beg, *end;
char temp;
beg = str;
end = str + len - 1;
@goctave
goctave / 3.c
Created April 18, 2012 01:38
CareerCup 1.3
/************************************
O(n^2)的算法
*************************************/
#include <stdio.h>
#include <string.h>
void unique(char str[])
{
int len = strlen(str);
int i, j;
@goctave
goctave / 4.c
Created April 19, 2012 02:40
CareerCup_1.4@1point3acres
#include <iostream>
#include <string>
using namespace std;
bool is_anagram(const string &str1, const string &str2)
{
if(str1.size() != str2.size())
return false;
int cnt1[256] = {0};
int cnt2[256] = {0};
@goctave
goctave / 5.cpp
Created April 20, 2012 05:41
CareerCup_1.5@1point3acres
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
void replace(char *str)
{
int n = 0;
int i;
for(i = 0; str[i] != '\0'; i++)
@goctave
goctave / 6.cpp
Created April 21, 2012 06:56
CareerCup_1.6@1point3acres
/*
Q: Given an image represented by an NxN matrix,
where each pixel in the image is 4 bytes, write
a method to rotate the image by 90 degrees
Can you do this in place?
*/
/*
C++传递二维数组比较麻烦
@goctave
goctave / 7.cpp
Created April 22, 2012 05:08
CareerCup_1.7@1point3acres
/*********************************************************************
Write an algorithm such that if an element in an MxN matrix is 0,
its entire row and column is set to 0
**********************************************************************/
#include <iostream>
using namespace std;
const int M = 4, N = 4;
@goctave
goctave / 2_1.cpp
Created April 24, 2012 03:15
CareerCup_2.1&2.2@1point3acres
/**********************************************************************
1.Write code to remove duplicates from an unsorted linked list
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?
2.Implement an algorithm to find the nth to last element of
a singly linked list. (method: find_n())
***********************************************************************/
@goctave
goctave / 2_3.cpp
Created April 26, 2012 02:44
CareerCup_2.3@1point3acres
#include <iostream>
using namespace std;
struct node
{
int data;
node *next;
node(): data(0), next(NULL){}
};
@goctave
goctave / main.cpp
Created May 3, 2012 03:58
CareerCup_3.3@1point3acres
//
// main.cpp
// cc3_3
//
// Created by kandia on 12-5-3.
// Copyright (c) 2012年 kandia. All rights reserved.
//
/*******************************************************************************
* Imagine a (literal) stack of plates If the stack gets too high, it might