Skip to content

[week39] 조천산 #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 조천산
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 1

### 문제 - <code>주식가격</code>
### 문제 - <code>짝지어 제거하기</code>

### 알고리즘 설계

Expand All @@ -9,25 +9,37 @@
### 풀이 코드

```jsx
function solution(prices) {
const len = prices.length;
const result = new Array(len).fill(0);
const stack = [];

for (let i = 0; i < len; i++) {
while (stack.length && prices[i] < prices[stack[stack.length - 1]]) {
let top = stack.pop();
let diff = i - top;
result[top] = diff;
}
stack.push(i);
class Stack {
constructor() {
this.storage = new Object();
this.size = 0;
}
while (stack.length) {
const top = stack.pop();
result[top] = len - 1 - top;
push(element) {
this.size++;
this.storage[this.size] = element;
}
pop() {
let removed = this.storage[this.size];
delete this.storage[this.size];
this.size--;
return removed;
}
top() {
return this.storage[this.size];
}

return result;
}
function solution(s) {
const stack = new Stack();
for (let i = 0; i < s.length; i++) {
if (stack.top() === s[i]) {
stack.pop();
continue;
} else {
stack.push(s[i]);
continue;
}
}
return stack.size > 0 ? 0 : 1;
}
```

Expand All @@ -41,32 +53,21 @@ function solution(prices) {

## 2

### 문제 - <code>스킬트리</code>
### 문제 - <code>튜플</code>

### 알고리즘 설계

### 풀이 코드

```jsx
function solution(skill, skill_trees) {
let result = 0;
function solution(s) {
let set = new Set();

for (const tree of skill_trees) {
const queue = [...skill];
let isValid = true;

for (const s of tree) {
if (skill.includes(s)) {
if (s !== queue[0]) {
isValid = false;
break;
}
queue.shift();
}
for (let i = 0; i < s.length; i++) {
if (isNaN(s[i]) === false) {
set.add(s[i]);
}
if (isValid) result++;
}
return result;
}
```

Expand Down
20 changes: 0 additions & 20 deletions week38/스킬트리.js

This file was deleted.

20 changes: 0 additions & 20 deletions week38/주식가격.js

This file was deleted.

32 changes: 32 additions & 0 deletions week39/짝지어제거하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Stack {
constructor() {
this.storage = new Object();
this.size = 0;
}
push(element) {
this.size++;
this.storage[this.size] = element;
}
pop() {
let removed = this.storage[this.size];
delete this.storage[this.size];
this.size--;
return removed;
}
top() {
return this.storage[this.size];
}
}
function solution(s) {
const stack = new Stack();
for (let i = 0; i < s.length; i++) {
if (stack.top() === s[i]) {
stack.pop();
continue;
} else {
stack.push(s[i]);
continue;
}
}
return stack.size > 0 ? 0 : 1;
}
File renamed without changes.
10 changes: 10 additions & 0 deletions week39/튜플.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function solution(s) {
let set = new Set();

for(let i = 0; i < s.length; i++){
if(isNaN(s[i])=== false){
set.add(s[i]);
}
}

}