
剑指offer
zwfars
这个作者很懒,什么都没留下…
展开
-
剑指offer 数组中的逆数对
链接:https://www.nowcoder.com/profile/8740530/codeBookDetail?submissionId=9156674来源:牛客网class Solution {public: int InversePairs(vector& data) { tem = data; int high = data.size()原创 2017-02-27 21:34:31 · 386 阅读 · 0 评论 -
剑指offer 二叉树中和为某一值的路径
class Solution {public: vector > FindPath(TreeNode* root, int expectNumber) { vector > ans; vector test; dfs(ans, test, root, expectNumber); return ans; } void dfs(vector > &ans, vector &t原创 2017-02-19 21:43:48 · 432 阅读 · 0 评论 -
剑指offer 复杂链表的复制
class Solution {public: RandomListNode* Clone(RandomListNode* pHead) { map aux; RandomListNode* cur = new RandomListNode(pHead->label); RandomListNode* head = cur; RandomListNode* tem = pHe原创 2017-02-20 20:09:14 · 283 阅读 · 0 评论 -
剑指offer 字符串的排列
class Solution {public: vector Permutation(string str) { sort(str.begin(), str.end()); string tem = str; vector ans; while (tem != "") { ans.push_back(tem); getnext(tem); } return原创 2017-02-21 20:41:48 · 233 阅读 · 0 评论 -
剑指offer 整数中1出现的次数(从1到n整数中1出现的次数)
class Solution {public: int NumberOf1Between1AndN_Solution(int n) { int divide = 1; int cur; int ans = 0; int pre; int remain; while (n >= divide) { remain = n % divide; pre = n /原创 2017-02-24 20:24:14 · 217 阅读 · 0 评论 -
剑指offer 把数组排成最小的数
bool mycmp(const string &A, const string &B){ return (A + B) < (B + A);}class Solution {public: string PrintMinNumber(vector numbers) { vector tem; string ans; int len = numbers.size();原创 2017-02-24 21:08:25 · 228 阅读 · 0 评论 -
剑指offer 丑数
class Solution {public: int GetUglyNumber_Solution(int index) { int cur1 = 0; int cur2 = 0; int cur3 = 0; vector tem; int cur; tem.push_back(1); for (int i = 1; i <= index; i++) { c原创 2017-02-24 21:55:25 · 251 阅读 · 0 评论 -
二叉树的深度
class Solution {public: int TreeDepth(TreeNode* pRoot) { if(!pRoot) return 0; return max(TreeDepth(pRoot->left),TreeDepth(pRoot->right))+1; }};原创 2017-02-24 23:31:04 · 219 阅读 · 0 评论 -
剑指offer 输入一棵二叉树,判断该二叉树是否是平衡二叉树。
class Solution {public: bool IsBalanced_Solution(TreeNode* root) { if(!root) return true; int tem = getheight(root->left) - getheight(root->right); int ans = (原创 2017-02-25 00:03:18 · 246 阅读 · 0 评论