摘要: 思路一:暴力解法,直接平方,然后添加到vector中 class Solution { public: vector<int> sortedSquares(vector<int>& A) { vector<int> res; if(A.size()==0){ return res; } for(au 阅读全文
posted @ 2019-06-22 17:25 菜鸟创业梦 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 题目讲解: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下: 1. 12. 113. 214. 12115. 111221 报数其实是根据前面一项进行报数.重复的就按照有几个几报数,但是要按顺序。 比如111,则为3个1, 121,则为1个1,1个2,1个1 ,因为 阅读全文
posted @ 2019-06-22 10:42 菜鸟创业梦 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 思路1:循环字符串,把左边各种括号压入栈。如果遇到右括号,则跟栈顶的符号比较。如果匹配,则栈顶元素出栈,不匹配则返回false class Solution { public: bool isValid(string s) { if(s=="")return true; stack<char> st 阅读全文
posted @ 2019-06-21 15:49 菜鸟创业梦 阅读(430) 评论(0) 推荐(0) 编辑
摘要: 方法一:递归操作。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ 阅读全文
posted @ 2019-06-21 10:41 菜鸟创业梦 阅读(583) 评论(0) 推荐(0) 编辑
摘要: 方法一: 思路:比如输入:strs = ["flower","flow","flight"] 先用strs[0]与strs[1]对比,得出最长公共前缀,然后再用此前缀去对比strs[3]. class Solution { public: string longestCommonPrefix(vec 阅读全文
posted @ 2019-06-12 16:26 菜鸟创业梦 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 方法1: 同时遍历两个链表,两个链表同时一对一相加,超过10就加到下一个加法集合。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) 阅读全文
posted @ 2019-06-04 18:28 菜鸟创业梦 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 方法1:暴力解决(最简单) class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> v; for(int i=0;i<nums.size();i++){ for(int j=i+ 阅读全文
posted @ 2019-06-04 14:44 菜鸟创业梦 阅读(137) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <string> using namespace std; string::size_type find_char(const string &s, char c, int &occurs) { auto ret = s.size(); oc 阅读全文
posted @ 2019-05-23 11:18 菜鸟创业梦 阅读(285) 评论(0) 推荐(0) 编辑
摘要: typedef struct BiTNode{ TElemType data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; typedef的定义: typedef为C语言的关键字,作用是为一种数据类型定义一个新名字。这里的数据类型包括内部数据类 阅读全文
posted @ 2019-05-05 20:40 菜鸟创业梦 阅读(7699) 评论(0) 推荐(0) 编辑
摘要: 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}。由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2。如果不存在则输出0。 方法一: 思路:对数组进行排序,然后利用辅助变量j来标识位置。 class S 阅读全文
posted @ 2019-04-23 15:56 菜鸟创业梦 阅读(204) 评论(0) 推荐(0) 编辑