-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bfa5c1
commit b7a8cb4
Showing
5 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
18 changes: 11 additions & 7 deletions
18
CrackingtheCodingInterview/1.ArraysandStrings/1.1 중복이 없는가/README.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
# 1. Arrays and Strings > 1.1 중복이 없는가 (Is Unique) | ||
# 1.1 중복이 없는가 (Is Unique) | ||
## 공부현황 (완료 시, 해당 칸에 공부한 날짜 적기) | ||
|
||
*`코드이해/분석` : CrackingtheCodingInterview 오픈소스 해답의 동작과정을 이해하고 모르는 것들을 정리했을 경우, 완료처리 | ||
|
||
*`복습` : 해답을 보지 않고 문제를 풀고, 모르는 것들을 다시 공부한 경우, 완료처리 | ||
|
||
*`내 것으로 만들기` : 해답을 보지 않고 문제를 풀었을 때 해답의 모든 경우를 다 풀 수 있는 경우, 완료처리 | ||
*`내 것으로 만들기` : 해답을 보지 않고 문제를 풀었을 때(손코딩) 해답의 모든 경우를 다 풀 수 있는 경우, 완료처리 | ||
|
||
|코드이해/분석| 복습 | 내 것으로 만들기| | ||
|:---:|:---:|:---:| | ||
|||| | ||
|제목|코드이해/분석| 복습 | 내 것으로 만들기| | ||
|:---:|:---:|:---:|:---:| | ||
|bitset|||| | ||
|brute_force|||| | ||
|vector|||| | ||
|sorting|||| | ||
|
||
## 해답종류 | ||
#### 1. biset 이용하는 방법 👉 [`isUnique_bitset`](https://github.com/witheunjin/PS/new/master) | ||
#### 2. DS 사용하지 않고 푸는 방법 👉 [`isUnique_noDS`](https://github.com/witheunjin/PS/new/master) | ||
#### 3. vector 사용해서 푸는 방법 👉 [`isUnique_vector`](https://github.com/witheunjin/PS/new/master) | ||
#### 2. 완전탐색을 이용하는 방법 👉 [`isUnique_bruteforce`](https://github.com/witheunjin/PS/new/master) | ||
#### 3. 동적배열을 사용해서 푸는 방법 👉 [`isUnique_vector`](https://github.com/witheunjin/PS/new/master) | ||
#### 4. 정렬해서 푸는 방법 👉 [`isUnique_sorting`](https://github.com/witheunjin/PS/new/master) | ||
|
This file contains 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
28 changes: 28 additions & 0 deletions
28
CrackingtheCodingInterview/1.ArraysandStrings/1.1 중복이 없는가/code/isUnique_bruteforce.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
bool isUnique_brute(const string &str) { | ||
for(int i=0; i<str.length()-1; ++i) { | ||
for(int j=i+1; j<str.length(); ++j) { | ||
if(str[i]==str[j]) { | ||
cout<<"character at index "<<i<<"(="<<str[i]<<") is same as "; | ||
cout<<"character at index "<<j<<"(="<<str[j]<<")"<<endl; | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int main() { | ||
cout<<"<isUnique :: brute force>"<<endl; | ||
string words[3] = {"apple", "mango", "kiwi"}; | ||
for(auto word : words) { | ||
cout<<"input : "<<word<<endl; | ||
cout<<"result : "; | ||
if(isUnique_brute(word)) cout<<"duplication doesn't exist"<<endl; | ||
else cout<<"duplication exists"<<endl; | ||
cout<<endl; | ||
} | ||
return 0; | ||
} |
This file contains 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
70 changes: 70 additions & 0 deletions
70
...dingInterview/1.ArraysandStrings/1.1 중복이 없는가/explanation/isUnique_bruteforce.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# isUnique_bruteforce | ||
|
||
### 📋 contents | ||
|
||
1. code : isUnique_brute() | ||
2. code : main() | ||
3. result | ||
|
||
----- | ||
|
||
#### 📝 사전지식(prior knowledge) | ||
|
||
*null* | ||
|
||
--------- | ||
|
||
## 1. code : isUnique_brute() | ||
|
||
```c++ | ||
bool isUnique_brute(const string &str) { | ||
for(int i=0; i<str.length()-1; ++i) { | ||
for(int j=i+1; j<str.length(); ++j) { | ||
if(str[i]==str[j]) { | ||
cout<<"character at index "<<i<<"(="<<str[i]<<") is same as "; | ||
cout<<"character at index "<<j<<"(="<<str[j]<<")"<<endl; | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
``` | ||
- **완전탐색(brute force)**을 이용하여 해결. | ||
- 시간복잡도는 **O(N)** *(N은 문자의 개수)* | ||
## 2. code : main() | ||
```c++ | ||
int main() { | ||
cout<<"<isUnique :: brute force>"<<endl; | ||
string words[3] = {"apple", "mango", "kiwi"}; | ||
for(auto word : words) { | ||
cout<<"input : "<<word<<endl; | ||
cout<<"result : "; | ||
if(isUnique_brute(word)) cout<<"duplication doesn't exist"<<endl; | ||
else cout<<"duplication exists"<<endl; | ||
cout<<endl; | ||
} | ||
return 0; | ||
} | ||
``` | ||
|
||
## 3. result | ||
|
||
``` | ||
<isUnique :: brute force> | ||
input : apple | ||
result : character at index 1(=p) is same as character at index 2(=p) | ||
duplication exists | ||
input : mango | ||
result : duplication doesn't exist | ||
input : kiwi | ||
result : character at index 1(=i) is same as character at index 3(=i) | ||
duplication exists | ||
``` | ||
|