-
-
Notifications
You must be signed in to change notification settings - Fork 245
[호돌이] Week5 #876
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
Merged
Merged
[호돌이] Week5 #876
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @param {number[]} prices | ||
* @return {number} | ||
*/ | ||
var maxProfit = function (prices) { | ||
// 초기 값 | ||
let buy = prices[0]; | ||
// 차액 | ||
let diff = 0; | ||
|
||
for (let i = 1; i < prices.length; i++) { | ||
// 구매가보다 현재가격이 더 싸면 구매가로 변경 | ||
if (buy > prices[i]) { | ||
buy = prices[i]; | ||
} | ||
// 차액 계산, 누가더 큰지 비교 | ||
diff = Math.max(diff, (prices[i] - buy)); | ||
|
||
} | ||
return diff | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @param {string[]} strs | ||
* @return {string[][]} | ||
*/ | ||
var groupAnagrams = function (strs) { | ||
// 정답 객체 | ||
let ans = {}; | ||
|
||
for (let s of strs) { | ||
// strs 배열에서 받아온 s를 하나씩 쪼개서 정렬, 다시 하나로 뭉침 | ||
let key = s.split('').sort().join(''); | ||
|
||
// 만약 정답 객체에 현재 단어가 없다? | ||
if (!ans[key]) { | ||
// 해당 값을 빈 배열로 초기화 | ||
ans[key] = []; | ||
} | ||
// 해당 값 배열에 초기 단어 추가. | ||
ans[key].push(s); | ||
} | ||
// 객체에 값을 추가한 것이기 때문에 Object.value()를 사용해서 열거 가능한 배열로 리턴 | ||
return Object.values(ans); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// trieNode 클래스 선언 | ||
// child = {}, end = false 로 초기화 | ||
class TrieNode { | ||
constructor(child = {}, end = false) { | ||
this.child = child; | ||
this.end = end; | ||
} | ||
} | ||
|
||
// Trie함수의 root는 TrieNode의 객체 | ||
var Trie = function() { | ||
this.root = new TrieNode(); | ||
}; | ||
|
||
/** | ||
* @param {string} word | ||
* @return {void} | ||
*/ | ||
// 단어 삽입 | ||
Trie.prototype.insert = function(word) { | ||
// 현재 = 최상단으로 초기화 | ||
let current = this.root; | ||
|
||
// 단어를 반복하면서 없으면 TrieNode에 추가 | ||
for (const char of word) { | ||
if (!current.child[char]) { | ||
current.child[char] = new TrieNode(); | ||
} | ||
current = current.child[char]; | ||
} | ||
|
||
// 반복이 끝나면 end true | ||
current.end = true; | ||
}; | ||
|
||
/** | ||
* @param {string} word | ||
* @return {boolean} | ||
*/ | ||
// 단어 탐색 | ||
Trie.prototype.search = function(word) { | ||
// 현재위치 = 최상단으로 | ||
let current = this.root; | ||
|
||
// 반복하면서 단어찾기 | ||
for(const char of word) { | ||
if(current.child[char]) { | ||
current = current.child[char]; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
return current.end; | ||
|
||
}; | ||
|
||
/** | ||
* @param {string} prefix | ||
* @return {boolean} | ||
*/ | ||
Trie.prototype.startsWith = function(prefix) { | ||
let current = this.root; | ||
for (const char of prefix) { | ||
if (current.child[char]) { | ||
current = current.child[char]; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
/** | ||
* Your Trie object will be instantiated and called as such: | ||
* var obj = new Trie() | ||
* obj.insert(word) | ||
* var param_2 = obj.search(word) | ||
* var param_3 = obj.startsWith(prefix) | ||
*/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에 개행문자가 누락되어있는 것 같아요.
개행문자 추가 후에도 혹시 통합 워크플로우에 문제가 있다면 디스코드나 코멘트 남겨주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
줄바꿈이 누락되어 통합테스트가 실패하고 있습니다! 수정하고 push부탁드립니다! @yeeZinu