随笔分类 -  面试中的数据结构算法题

摘要:#include <iostream> #include <vector> using namespace std; void merge_sort(vector<int>& vec,int left, int right); int main(){ vector<int> input = {}; 阅读全文
posted @ 2021-04-14 12:12 zeroPatrick 阅读(28) 评论(0) 推荐(0)
摘要:最长递增子序列 给定数组arr,设长度为n,输出arr的最长递增子序列。(如果有多个答案,请输出其中字典序最小的) 输入描述 输出两行,第一行包括一个正整数n(n<=100000),代表数组长度。第二行包括n个整数,代表数组arr \left(1 \leq arr_i \leq 1e9 \right 阅读全文
posted @ 2021-04-09 20:06 zeroPatrick 阅读(1037) 评论(0) 推荐(0)
摘要:二分查找使用:left + (right - left) / 2,避免(left+right)出现溢出 阅读全文
posted @ 2021-01-15 23:27 zeroPatrick 阅读(1473) 评论(0) 推荐(0)
摘要:求解 x的n次方 class Solution { public: double myPow(double x, int n) { if(n == 0 || x == 1) return 1; double ans = 1; long k = n; if(k < 0){ k = -k; x = 1/ 阅读全文
posted @ 2021-01-07 17:41 zeroPatrick 阅读(35) 评论(0) 推荐(0)
摘要:转载自:https://www.cnblogs.com/1miharu/p/11333297.html /* 底数 指数(二进制) sum 初始 3 1101 3^1 3^2 110 3^1 3^4 11 3^1 * 3^4 3^8 1 3^1 * 3^4 * 3^8 --> 3^13 */ #in 阅读全文
posted @ 2021-01-07 17:40 zeroPatrick 阅读(73) 评论(0) 推荐(0)
摘要:转载自:https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/solution/4chong-jie-fa-di-gui-zhan-dui-lie-by-sdwwld/ 方法一:使用栈解决 如果使用栈来解决首先要搞懂一个知识点,就是前 阅读全文
posted @ 2021-01-07 14:10 zeroPatrick 阅读(192) 评论(0) 推荐(0)
摘要:ListNode* reversePrint(ListNode* head) { //*******************链表反转********************* ListNode* last = nullptr; ListNode* cur = head; while(cur != n 阅读全文
posted @ 2021-01-06 20:56 zeroPatrick 阅读(39) 评论(0) 推荐(0)
摘要:需重点考虑以下两种情况: 90 90 80 80 60 20 50 50 50 10 10 40 30 20 90 90 90 40 40 80 30 70 70 70 20 60 15 10 10 阅读全文
posted @ 2020-12-31 13:48 zeroPatrick 阅读(254) 评论(0) 推荐(0)
摘要:转载自:https://leetcode-cn.com/problems/longest-palindromic-substring/solution/zhong-xin-kuo-san-dong-tai-gui-hua-by-liweiwei1419/ 阅读全文
posted @ 2020-12-28 14:38 zeroPatrick 阅读(120) 评论(0) 推荐(0)
摘要:前序 class Solution { public: vector<int> preorderTraversal(TreeNode* root) { vector<int> res; if (root == nullptr) { return res; } stack<TreeNode*> stk 阅读全文
posted @ 2020-12-28 12:41 zeroPatrick 阅读(135) 评论(0) 推荐(0)
摘要:参考链接:https://baike.baidu.com/item/%E5%B0%BE%E9%80%92%E5%BD%92/554682?fr=aladdin 如果一个函数中所有递归形式的调用都出现在函数的末尾,我们称这个递归函数是尾递归的。当递归调用是整个函数体中最后执行的语句且它的返回值不属于表 阅读全文
posted @ 2020-12-21 20:10 zeroPatrick 阅读(99) 评论(0) 推荐(0)
摘要:question description: solution with C++: vector<int> Solution::poker(vector<int> desk) { if (desk.size() == 0) { return {}; } deque<int> hand; //手中的牌 阅读全文
posted @ 2020-12-17 20:26 zeroPatrick 阅读(54) 评论(0) 推荐(0)