Code Force 273 (Div2)
Question A Very simple and naive question. One thing worth noticing is that . int main(){ int sum = 0; int tp; for(int i = 0; i < 5; ++ i){ cin >> tp; sum += tp; } if (sum%5...
Question A Very simple and naive question. One thing worth noticing is that . int main(){ int sum = 0; int tp; for(int i = 0; i < 5; ++ i){ cin >> tp; sum += tp; } if (sum%5...
Description https://oj.leetcode.com/problems/3sum/ Difficulty: 3.0/5.0 Solution 3Sum is an extension to 2Sum. We are required to get all non-redundant triplets whose sum is zero. In this case, we enumerate each unqiue left elemenet in a triplet and use the 2Sum algorithm...
Description https://oj.leetcode.com/problems/3sum-closest/ Difficulty: 2.5/5.0 Solution Very Samilar with 3sum. class Solution { public: int threeSumClosest(vector<int> &num, int target) { int left = 0; int minDiff = INT_MAX; int bestSum = 0; sort(num.begin(), num.end()); while(left < ((int)num.size()-2)){ int mid = left...
Description https://oj.leetcode.com/submissions/detail/13239400/ Difficulty: 1.0/5.0 Solution Note that the corner case where nRow = 1 has to be addressed at the beginning. class Solution { public: string convert(string s, int nRows) { if (nRows == 1) return s; string re; int...
Descripition https://oj.leetcode.com/submissions/detail/13248579/ Difficutly: 2.0/5.0 Solution It is much easier and faster to solve this problem following a bottom-up manner, which can be viewed as a tree DP problem. class Solution { public: int minimumTotal(vector<vector<int> > &triangle) { if (triangle.size() ==...