LeetCode
koilin
这个作者很懒,什么都没留下…
展开
-
709. 转换成小写字母
std::string Algorithm::toLowerCase(string str){ string strNew; int nStr = str.length(); for (int iStr = 0; iStr < nStr; iStr++) { char ch = str[iStr]; if (ch >= 'A' && ch <=...原创 2018-12-12 17:22:35 · 137 阅读 · 0 评论 -
14. 最长公共前缀
std::string Algorithm::longestCommonPrefix(vector<string>& strs){ std::string strCommon; int iSz = strs.size(); if (iSz >= 1) { strCommon = strs.at(0); } for (int i = 0; i <...原创 2018-12-18 10:15:42 · 112 阅读 · 0 评论 -
94. 二叉树的中序遍历
std::vector<int> Algorithm::inorderTraversal(TreeNode* root){ std::vector<int> vecVals; TreeNode* pCur = root; std::stack<TreeNode*> stTree; while (pCur != NULL || !stTree....原创 2018-12-18 09:54:23 · 133 阅读 · 0 评论 -
771. Jewels and Stones
int Algorithm::numJewelsInStones(string J, string S){ int nCount = 0; int nJ = J.length(); int nS = S.length(); map<char, int> mapCount; map<char, int>::iterator itorKey; for (int ...原创 2018-12-11 19:06:17 · 240 阅读 · 1 评论 -
763. 划分字母区间
std::vector<int> Algorithm::partitionLabels(string S){ std::vector<int> vecMins; std::vector<int> vecMaxs; bool arrayBFirst[26]; for (int i = 0; i < 26; i++) { arrayBFirs...原创 2018-12-17 19:29:05 · 232 阅读 · 0 评论 -
814. 二叉树剪枝
TreeNode* Algorithm::pruneTree(TreeNode* root){ bool bCut = true; while (bCut) { std::stack<TreeNode*> stRoot; TreeNode* pCur = root; TreeNode* pPre = nullptr; stRoot.push(root);...原创 2018-12-17 17:08:40 · 419 阅读 · 0 评论 -
657. 机器人能否返回原点
bool Algorithm::judgeCircle(string moves){ int px = 0; int py = 0; int nLen = moves.length(); for (int i = 0; i < nLen; i++) { char ch = moves.at(i); switch (ch) { case 'L': px -=...原创 2018-12-17 15:23:57 · 148 阅读 · 0 评论 -
13. 罗马数字转整数
int nLen = s.length(); bool bAtEnd = false; bool bAhead = false; int nSum = 0; for (int i = 0; i < nLen; i++) { char ch = s.at(i); char chN = 'a'; if (i == nLen - 1) { bAtEnd = tru...原创 2018-12-17 14:52:20 · 103 阅读 · 0 评论 -
4. 寻找两个有序数组的中位数
double Algorithm::findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2){ int m = nums1.size(); int n = nums2.size(); int nCount = (m + n) / 2; int nLast = (m + n) % ...原创 2018-12-20 19:16:36 · 320 阅读 · 0 评论 -
9. 回文数
bool Algorithm::isPalindrome(int x){ if (x < 0) return false; else if (x == 0) { return true; } int resX = 0; int iLast = 0; int iDev = 10; int iCount = 0; std::vector<int> v...原创 2018-12-14 14:12:41 · 120 阅读 · 0 评论 -
832. 翻转图像
std::vector<std::vector<int>> Algorithm::flipAndInvertImage(vector<vector<int>>& A){ vector<vector<int>>::iterator itorArray = A.begin(); for (; itorArray !...原创 2018-12-12 19:21:35 · 108 阅读 · 0 评论 -
595. 大的国家
select name, population, area from World where area > 3000000 or population > 25000000;原创 2018-12-12 18:41:56 · 112 阅读 · 0 评论 -
905. 按奇偶排序数组
std::vector<int> Algorithm::sortArrayByParity(vector<int>& A){ vector<int>::iterator itor = A.begin(); vector<int> vecOdd; vector<int> vecEven; vector<int>...原创 2018-12-12 18:24:55 · 117 阅读 · 0 评论 -
929. 独特的电子邮件地址
int Algorithm::numUniqueEmails(vector<string>& emails){ map<string, bool> mapEmail; vector<string>::iterator itorEmail = emails.begin(); for (; itorEmail != emails.end(); it...原创 2018-12-12 10:21:39 · 657 阅读 · 0 评论