摘要:
DP.类似最大和。就是要记录正的和负的两种情况。class Solution {public: int maxProduct(int A[], int n) { vector positive(n); vector minus(n); int resu... 阅读全文
摘要:
二分class Solution {public: /* test: [1] test: [2, 1] test: [3, 1, 2] test: [2, 3, 1] test: [3, 4, 1, 2] test: [3, 4, 5, 1, 2] *... 阅读全文
摘要:
二分,各种情况。class Solution {public: int findMin(vector &num) { int size = num.size(); int minVal = num[size-1]; findMinRe(num, 0, ... 阅读全文
摘要:
老题目。两个栈。class MinStack { stack stk; stack minstk;public: void push(int x) { stk.push(x); if (minstk.empty() || minstk.top() >= ... 阅读全文
摘要:
老题了。class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *tailA = headA; ListNode *tail... 阅读全文
摘要:
类似二分。class Solution {public: int findPeakElement(const vector &num) { int size = num.size(); int left = 0; int right = size - ... 阅读全文
摘要:
用分桶的做法,思路参考自网友,很精妙。class Solution {public: int maximumGap(vector &num) { int size = num.size(); if (size minBucket(bucketSize, INT_M... 阅读全文
摘要:
本人的做法是转化成vector再处理,各种情况就比较简单了。class Solution {public: int compareVersion(string version1, string version2) { vector v1 = convert(version1); ... 阅读全文
摘要:
各种情况。有恶心的负数最值,用long long来做了。除此之外的情况下面都列出来了。/*1, 8 = 0.1251, 6 = 0.1(6)-50, 6 = -6.250, -3 = 0-1, -2147483648 = "0.0000000004656612873077392578125"*/ty... 阅读全文
摘要:
这道题,其实不简单。知道是26进制,怎么能够找规律找到+-1的位置呢?思路是去找 比如,AAB到AB的表达式的不变的地方,找到递推式。class Solution {public: string convertToTitle(int n) { string result; ... 阅读全文
摘要:
黑帮火并简单版。多个数的有另一篇文章。class Solution {public: int majorityElement(vector &num) { int size = num.size(); int major = 0; int count ... 阅读全文
摘要:
本质是26进制,注意每次+1.class Solution {public: int titleToNumber(string s) { int size = s.size(); int num = 0; for (int i = 0; i < siz... 阅读全文
摘要:
老题,简单题。数5的个数就行了。class Solution {public: int trailingZeroes(int n) { int result = 0; while (n > 0) { result += n / 5; ... 阅读全文
摘要:
使用栈来记录可能的路径,栈顶一直是下一个元素。 class BSTIterator { public: stack<TreeNode *> path; BSTIterator(TreeNode *root) { path = stack<TreeNode *>(); TreeNode *node = 阅读全文