본문 바로가기

전체 글67

953. Verifying an Alien Dictionary class Solution { public: bool isAlienSorted(vector& words, string order) { int mapping[26]; for (int i = 0; i < 26; ++i) mapping[order[i] - 'a'] = i; for (auto& w : words) { for (auto& c : w) { c = mapping[c - 'a']; } } return is_sorted(words.begin(), words.end()); } }; 특수한 order를 일반적인 order로(integer order) 변환 2022. 9. 15.
1588. Sum of All Odd Length Subarrays class Solution { public: int sumOddLengthSubarrays(vector& arr) { int n = arr.size(); int ans = 0; for (int i = 0; i < n; ++i) { int k = (i + 1) * (n - i); // total_left * total_right k = ((i+2)/2)*((n-i+1)/2) + ((i+1)/2)*((n-i)/2); //cout 2022. 9. 13.
496. Next Greater Element I class Solution { public: vector nextGreaterElement(vector& nums1, vector& nums2) { unordered_map greater; stack left; for (auto n : nums2) { while (!left.empty() && left.top() < n) { greater[left.top()] = n; left.pop(); } left.push(n); } vector ans(nums1.size()); for (int i = 0; i < nums1.size(); ++i) { ans[i] = greater.count(nums1[i]) ? greater[nums1[i]] : -1; } return ans; } }; 2022. 9. 13.
reverse 1 #include #include char code1[] = { "\x55\x8b\xec\x83\xec\x48\xc7\x45\xf4\x63\x61\x6c\x63\xc7\x45\xf8" "\x00\x00\x00\x00\x6a\x01\x8d\x45\xf4\x50\xa1" "\x00\x80\x41\x00" "\xff\xd0\x6a\x00\xa1" "\xfc\x80\x41\x00" "\xff\xd0" }; char code2[] = { "\x55\x8b\xec\x83\xec\x48\xc7\x45\xf4\x63\x61\x6c\x63\xc7\x45\xf8" "\x00\x00\x00\x00\x6a\x01\x8d\x45\xf4\x50\xa1" "\x00\x80\x41\x00" "\xff\xd0\x6a\x00\xa1" ".. 2022. 9. 6.