上一页 1 ··· 7 8 9 10 11 12 下一页
摘要: 还是用了暴力算法,因为别的写不出来,效率极低,nnd,贴代码 class Solution { public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { int m = nums1.size(); int n = 阅读全文
posted @ 2021-03-05 20:50 zhaohhhh 阅读(39) 评论(0) 推荐(0)
摘要: 第一个方法,现学现卖,先排序,排完序了再遍历,找没有重复的 class Solution { public: int singleNumber(vector<int>& nums) { sort(nums.begin(),nums.end()); int n = nums.size(); if(n= 阅读全文
posted @ 2021-03-05 17:45 zhaohhhh 阅读(51) 评论(0) 推荐(0)
摘要: 思路是很简单,用了一个哈希表解决了问题,要是隔以前估计真想不出来怎么做。下面上用map的代码 class Solution { public: bool containsDuplicate(vector<int>& nums) { map<int,int> good; int n = nums.si 阅读全文
posted @ 2021-03-05 17:14 zhaohhhh 阅读(45) 评论(0) 推荐(0)
摘要: 一个有点困难的题目,因为在正确的道路上走了岔路,所以没写出来。 先是最简单的解法,重新创建一个同样大的数组用来存放经过移位的数据,然后再复制过去,简单易懂。贴代码 class Solution { public: void rotate(vector<int>& nums, int k) { int 阅读全文
posted @ 2021-03-04 17:04 zhaohhhh 阅读(55) 评论(0) 推荐(0)
摘要: 思路不是特别难,双指针就能解决问题,写的时候最大的困扰在于边界条件不清晰导致的数组越界。贴暴力代码 class Solution { public: int maxProfit(vector<int>& prices) { int earn = 0; int n = prices.size(); i 阅读全文
posted @ 2021-03-03 21:46 zhaohhhh 阅读(46) 评论(0) 推荐(0)
摘要: 很简单,但是做的时候给自己加了很多限制条件,所以花了比较多的时间,实际上双指针能够很快的解决问题,上代码 class Solution { public: int removeDuplicates(vector<int>& nums) { if(nums.size()<2) return nums. 阅读全文
posted @ 2021-03-03 18:26 zhaohhhh 阅读(53) 评论(0) 推荐(0)
摘要: 搞暴力算法也能搞出来,而且不大困难,这个题最主要的问题是第一次接触了动态规划的东西,具有一定的历史意义。下面先贴暴力代码 class Solution { public: string longestPalindrome(string s) { int n = s.length(); int i = 阅读全文
posted @ 2021-03-02 19:57 zhaohhhh 阅读(60) 评论(0) 推荐(0)
摘要: 主要功能为实现一个类,能够从文件中读取英文字符串,包含一个功能函数,其效果为从两个字符串中找到最长的共同单词,下面贴代码 #include <iostream> #include<fstream> #include<iomanip> using namespace std; // //类定义 // 阅读全文
posted @ 2021-02-21 15:47 zhaohhhh 阅读(216) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; template <typename T> int binary_search(T* a,T b,int left,int right) { int mid = (left + right) / 2; if (b > 阅读全文
posted @ 2021-02-20 20:19 zhaohhhh 阅读(98) 评论(0) 推荐(0)
摘要: 先上自己的暴力算法,执行的结果是时间效率较差,那就应该有啥比较灵活的做法。 class Solution { public: int lengthOfLongestSubstring(string s) { int sign = 0; int j = 1; int max = 0; for(int 阅读全文
posted @ 2021-02-18 15:39 zhaohhhh 阅读(39) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 下一页