전체 글
-
804. Unique Morse Code Words릿코드(LEETCODE) 2020. 3. 5. 07:35
https://leetcode.com/problems/unique-morse-code-words class Solution { public: int uniqueMorseRepresentations(vector& words) { vector morse = {".-","-...","-.-.","-..",".","..-.","--.", "....","..",".---","-.-",".-..","--","-.", "---",".--.","--.-",".-.","...","-","..-", "...-",".--","-..-","-.--","--.."}; map m; for(int i=0; i
-
1252. Cells with Odd Values in a Matrix릿코드(LEETCODE) 2020. 3. 3. 21:10
https://leetcode.com/problems/cells-with-odd-values-in-a-matrix Wrong Source 문제 잘못이해해서 해당 좌표 주위로 4 방향으로 채우는 문제로 착각.. class Solution { public: int table[51][51]; int oddCells(int n, int m, vector& indices) { for (int i = 0; i = 0) table[y - 1][x]++; if (y + 1 = 0) table[y][x - 1]++; if ..
-
1207. Unique Number of Occurrences릿코드(LEETCODE) 2020. 3. 3. 11:39
https://leetcode.com/problems/unique-number-of-occurrences/ 각 숫자의 요소의 갯수가 유일한지 판단하는 문제 class Solution { public: unordered_map m; bool check(int count) { return m.count(count); } bool uniqueOccurrences(vector& arr) { sort(arr.begin(), arr.end()); int prev = arr[0]; int prev_count = 0; for (int i = 0; i < arr.size(); i++) { int current = arr[i]; if (prev == current) { prev_count++; } else { if (ch..
-
1365. How Many Numbers Are Smaller Than the Current Number릿코드(LEETCODE) 2020. 3. 3. 11:37
https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ class Solution { public: vector smallerNumbersThanCurrent(vector& nums) { vector ret; for (int i = 0; i nums[j]) { cnt++; } } ret.push_back(cnt); } return ret; } };
-
1366. Rank Teams by Votes릿코드(LEETCODE) 2020. 3. 3. 11:33
https://leetcode.com/problems/rank-teams-by-votes/ a~z 까지 알파벳의 가중치의 합과 정렬을 이용 struct Ele { char ch; vector cnt; Ele() { cnt.resize(26, 0); } }; bool operator b.cnt; return a.ch < b.ch; } class Solution { public: string rankTeams(vector& votes) { map my; for (int i = 0; i < votes.size(); ++i) { for (int j = 0; j < votes[i].size()..
-
733. Flood Fill릿코드(LEETCODE) 2020. 3. 3. 11:32
https://leetcode.com/problems/flood-fill/ sr, sc row, col 의 크기가 다를 수 있음을 주의 const int dx[] = { -1, 0, 0, 1 }; const int dy[] = { 0, -1, 1, 0 }; class Solution { public: void dfs(vector& image, int sr, int sc, int newColor, int dstColor) { image[sr][sc] = newColor; for (int i = 0; i = image[0].size()) { continue; } if (cy < 0..
-
463. Island Perimeter릿코드(LEETCODE) 2020. 3. 3. 11:30
https://leetcode.com/problems/island-perimeter/ 현재위치에서 4방향으로 이웃한 점이 있다면 그 개수만큼 - class Solution { public: int islandPerimeter(vector& grid) { int count = 0; int rows = grid.size(); int cols = grid[0].size(); for (int i = 0; i = 0 && grid[i - 1][j]) count--; if (i + 1 < rows && grid[i + 1][j]) count--; i..
-
1207. Unique Number of Occurrences릿코드(LEETCODE) 2020. 2. 28. 17:05
https://leetcode.com/problems/unique-number-of-occurrences 이전값고 다를때 hash 내의 중복수가 있는지 확인하고 없으면 hash 에 삽입 있으면 중복된 카운트가 있음으로 false 를 리턴 한다. class Solution { public: unordered_map m; bool check(int count) { return m.count(count); } bool uniqueOccurrences(vector& arr) { sort(arr.begin(), arr.end()); int prev = arr[0]; int prev_count = 0; for (int i = 0; i < arr.size(); i++) { int current = arr[i]; if..