摘要: There are some chips, and the i-th chip is at position chips[i]. You can perform any of the two following types of moves any number of times (possibly 阅读全文
posted @ 2019-10-07 20:09 rarecu 阅读(253) 评论(0) 推荐(0) 编辑
摘要: Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that th 阅读全文
posted @ 2019-10-07 20:03 rarecu 阅读(158) 评论(0) 推荐(0) 编辑
摘要: In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the ma 阅读全文
posted @ 2019-10-07 19:51 rarecu 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 1. numpy求数组的最小k个数: np.argpartition(arr, k) 做的是快排中的f分区步骤,它不改变原来的数组,只会返回分区好之后的数组的索引,保证前 k -1 个索引对应的元素 < = 第k个;例如: > arr= np.array([1, 3, 5, 4, 6, 2, 8]) 阅读全文
posted @ 2019-09-19 09:27 rarecu 阅读(569) 评论(0) 推荐(0) 编辑
摘要: 1. 贪心,回溯。从最后一个位置往前找,如果有一个i,它走得最远能够到达或超过我们现在所在的位置,那就把它当作上一步,直到找到最前面。如果最前面是第一步,说明可以沿着刚才的路径到达最后,否则不行。 2. 贪心思想,递归做法。从第一个位置往后找,当前位置是now,如何确定next在哪一个? 在当前所有 阅读全文
posted @ 2019-09-15 16:41 rarecu 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 思路: 是否合法,最简单判断方法是用栈。只有一种括号,栈中存放元素只需要左括号的下标。 每一次遇到),就把栈顶的一个左括号下标和当前下标一起压入vector中,将这个vector排序,就是所有合法子串的下标。遍历这个vector,找连续的最长值就可以。排序复杂度O(nlogn),除此之外遍历一次字符 阅读全文
posted @ 2019-09-15 15:59 rarecu 阅读(516) 评论(0) 推荐(0) 编辑
摘要: // left是当前可用的左括号数,right是当前可用的右括号数,思路就是从左到右地找每一种可能。 // 当前,如果left==right的话,下一个字符一定只能是“(” //如果left> threeSum(vector& nums) { sort(nums.begin(),nums.end()); vector> result; for(in... 阅读全文
posted @ 2019-09-15 01:01 rarecu 阅读(247) 评论(0) 推荐(0) 编辑
摘要: //解法一,map将数组分成n,0,p三组,寻找9(0,0,0),(n,0,p)(n,n,p)和(p,p,n)的组合,但是因为不可重复,所以最后两种组合比较麻烦,复杂度是O(n^2),遍历多次,最后两个case TLE class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { map<int,int> ne 阅读全文
posted @ 2019-09-15 00:30 rarecu 阅读(476) 评论(0) 推荐(0) 编辑
摘要: //第一种解法,遍历一次数长度,然后把头尾相连,再遍历一次 class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode* tem=head; int len=0; while(tem->next){ //这里得到的长度是真实... 阅读全文
posted @ 2019-09-14 22:00 rarecu 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 机器学习模型 @(实验室)[笔记] 学习资料 https://datawhalechina.github.io/leeml notes 李宏毅机器学习课笔记 https://www.bilibili.com/video/av59538266/?p=6 李宏毅课程的视频 问题类型:regression 阅读全文
posted @ 2019-09-08 17:16 rarecu 阅读(402) 评论(0) 推荐(0) 编辑