Skip to content
Merged
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
41 changes: 41 additions & 0 deletions best-time-to-buy-and-sell-stock/Hyeri1ee.java
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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 prices[0]으로 초기화했는데 이렇게 시작하는 방법도 좋네요! 👍🏻

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;

}

}

30 changes: 30 additions & 0 deletions group-anagrams/Hyeri1ee.java
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;
}
}

Loading