diff --git a/best-time-to-buy-and-sell-stock/Hyeri1ee.java b/best-time-to-buy-and-sell-stock/Hyeri1ee.java new file mode 100644 index 0000000000..757cac6ddb --- /dev/null +++ b/best-time-to-buy-and-sell-stock/Hyeri1ee.java @@ -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; + + } + +} + diff --git a/group-anagrams/Hyeri1ee.java b/group-anagrams/Hyeri1ee.java new file mode 100644 index 0000000000..d5fec4a6e2 --- /dev/null +++ b/group-anagrams/Hyeri1ee.java @@ -0,0 +1,30 @@ +import java.util.*; + +class Solution { + //static HashMap< + public List> groupAnagrams(String[] strs) { + HashMap> 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 = new ArrayList<>(); + for(List group : map.values()){ + list.add(group); + } + + return list; + } +} +