-
-
Notifications
You must be signed in to change notification settings - Fork 340
[Hyeri1ee] WEEK 05 Solutions #2504
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
+71
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,41 @@ | ||
| class Solution { | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| //O(n)에 증가 한 경우 profitMax를 갱신시키며 판단 -> time limit | ||
| public int maxProfit(int[] prices) { | ||
| int profitMax = 0; | ||
| /* | ||
| for(int i=0; i< prices.length - 1; i++){ | ||
| int buy= prices[i]; | ||
|
|
||
|
|
||
| for(int d =i+1; d < prices.length; d++){ | ||
| int sellCandid = prices[d]; | ||
| if (sellCandid - buy > profitMax){ | ||
| profitMax = sellCandid - buy; | ||
| } | ||
|
|
||
| } | ||
| }//end of for | ||
|
|
||
| */ | ||
|
|
||
| int priceMin = Integer.MAX_VALUE; | ||
| for(int i =0; i < prices.length; i++){ | ||
| if (prices[i] < priceMin){ | ||
| priceMin = prices[i]; | ||
| } | ||
| else{ | ||
| profitMax = Math.max(profitMax, prices[i] - priceMin); | ||
| } | ||
| } | ||
|
|
||
| return profitMax; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
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,30 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| //static HashMap< | ||
| public List<List<String>> groupAnagrams(String[] strs) { | ||
| HashMap<String, List<String>> map = new HashMap<>(); | ||
|
|
||
| for(int w = 0 ;w < strs.length; w++){ | ||
| String word = strs[w]; | ||
| char[] arr = word.toCharArray(); | ||
|
|
||
| //정렬한거 | ||
| Arrays.sort(arr); | ||
| String newWord = new String(arr); | ||
|
|
||
| map.putIfAbsent(newWord, new ArrayList<>()); | ||
| map.get(newWord).add(word); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| List<List<String>> list = new ArrayList<>(); | ||
| for(List<String> group : map.values()){ | ||
| list.add(group); | ||
| } | ||
|
|
||
| return list; | ||
| } | ||
| } | ||
|
|
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.
저는 prices[0]으로 초기화했는데 이렇게 시작하는 방법도 좋네요! 👍🏻