This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************** | |
1.最简单的方法就是两层循环,复杂度O(n^2) | |
2.使用排序,然后找重复。复杂度为O(nlgn)+O(n)=O(nlgn) | |
3.直接使用快排,在排序过程中,如果发现有重复的,立即结束递归 | |
****************************************************/ | |
#include <stdio.h> | |
#include <string.h> | |
int repeat; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************ | |
O(n^2)的算法 | |
*************************************/ | |
#include <stdio.h> | |
#include <string.h> | |
void unique(char str[]) | |
{ | |
int len = strlen(str); | |
int i, j; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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++传递二维数组比较麻烦 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************* | |
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
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()) | |
***********************************************************************/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct node | |
{ | |
int data; | |
node *next; | |
node(): data(0), next(NULL){} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
OlderNewer