摘要: bool cmp (int i,int j) { return (i>j);} class Solution { public: int hIndex(vector& citations) { int count = 0; sort(citations.begin(),citations.end(),cmp); for(int i = ... 阅读全文
posted @ 2018-08-18 16:10 Lokianyu 阅读(209) 评论(0) 推荐(0)
摘要: A. Single Wildcard Pattern Matching 题目链接:A. Single Wildcard Pattern Matching 题意:给定两个字符串,第一个字符串至多含有一个*,然后可以把*替换成一个任意的字符串,求这两个字符串是否匹配。 思路:首先判断是否含有'*',没有 阅读全文
posted @ 2018-08-18 09:55 Lokianyu 阅读(89) 评论(0) 推荐(0)
摘要: 因为时间序列有序,从后往前遍历一次,总时间要么是前一个时间点减后一个时间点,要么是吃满中毒持续时间。 class Solution { public: int findPoisonedDuration(vector<int>& timeSeries, int duration) { int coun 阅读全文
posted @ 2018-08-17 22:22 Lokianyu 阅读(106) 评论(0) 推荐(0)
摘要: 思路就是三重循环遍历即可,反正不卡时间复杂度(逃 class Solution { public: int triangleNumber(vector<int>& nums) { int count = 0; for(int i = 0; i < nums.size(); i++) for(int 阅读全文
posted @ 2018-08-17 21:58 Lokianyu 阅读(380) 评论(0) 推荐(0)
摘要: 此题就是一个深度优先搜索的实例,遍历一遍池塘,将凡是有水的周围的八个格子进行DFS使所有'W'变成'.',这样进行了几次DFS,就有几片池塘。具体如代码。 题目链接:POJ 2386 Lake Counting 阅读全文
posted @ 2018-08-13 13:32 Lokianyu 阅读(148) 评论(0) 推荐(0)
摘要: A.The Rank 读完题后的第一思路自然是算出总和后用qsort进行主次关键字排序(qsort的多种用法)。 题目链接:A.The Rank AC代码: B.The Bits 读后可知是要将二进制数a的两个位置的数互换后使其与b的按位或值发生改变。 由于除了0|0 == 0 其它都为1,而且b的 阅读全文
posted @ 2018-08-09 14:04 Lokianyu 阅读(192) 评论(0) 推荐(0)