C++
文章平均质量分 63
vvickey11
一个热爱计算机,喜欢不断面对困难,迎接挑战的孩纸!↖(^ω^)↗,哈尔滨工业大学硕士在读
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
434. Number of Segments in a String
class Solution {public: int countSegments(string s) { int count = 0 ; int len = s.size(); for(int i = 0 ; i < len ; i++ ){ if(s[i] == ' '){ co原创 2017-07-10 14:46:59 · 274 阅读 · 0 评论 -
38. Count and Say
class Solution {public: string countAndSay(int n) { if( n <= 0){ return NULL; } string dp[n]; dp[0] = "1"; string now; string newstr;原创 2017-05-09 16:12:57 · 200 阅读 · 0 评论 -
Valid Palindrome
class Solution {public: bool isPalindrome(string s) { int len = s.size(); if(len <= 1){ //记住回文数长度为1,是回文数 return true; } bool ti = false ,tj原创 2017-05-17 20:04:28 · 211 阅读 · 0 评论 -
136. Single Number
class Solution {public: int singleNumber(vector& nums) { int temp = 0; //用异域的思想,出现两次的数就是最后异域为0,只有全部异域之后剩下的就是出现次数为1的元素 for(int i = 0 ; i < nums.size() ;i++){ te原创 2017-05-17 16:42:48 · 204 阅读 · 0 评论 -
141. Linked List Cycle
点击打开链接上面的参考的答案/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public原创 2017-05-17 16:03:42 · 215 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas原创 2017-05-17 15:07:07 · 203 阅读 · 0 评论 -
35. Search Insert Position
class Solution {public: int searchInsert(vector& nums, int target) { int len = nums.size(); if(len == 0){ return 0; } if(target < nums[0] || target ==原创 2017-05-08 21:29:56 · 220 阅读 · 0 评论 -
28. Implement strStr()
class Solution {public: int strStr(string haystack, string needle) { int len1 = haystack.size(); int len2 = needle.size(); int i = 0 ; int index; //当两个序列的原创 2017-05-08 21:00:41 · 204 阅读 · 0 评论 -
221. Maximal Square
class Solution {public: int maximalSquare(vector>& matrix) { int rows = matrix.size(); if(rows == 0) return 0; int cols = matrix[0].size(); vector > dp原创 2017-05-07 22:45:58 · 213 阅读 · 0 评论 -
LeetCode Triangle
class Solution {public: int minimumTotal(vector>& triangle) { int rows = triangle.size(); int res; if (rows<1){ return 0; } if (rows == 1){ return triangle[0][0]; } int dp[1000][原创 2017-05-06 22:50:37 · 188 阅读 · 0 评论 -
Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* ad原创 2017-04-24 21:32:18 · 233 阅读 · 0 评论 -
58. Length of Last Word
class Solution {public: int lengthOfLastWord(string s) { int len = s.size(); int res = 0; if(len == 0){ return 0; } for(int i = len -1 ; i>=0 ;原创 2017-05-09 20:15:50 · 188 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
class Solution {public: int maxProfit(vector& prices) { //这道题我想的太复杂了,其实就是从头开始,只要后项大于前项就把数据加入到结果中, //多次交易的累和,只能向后计算 //贪心算法 int len = prices.size(); int res原创 2017-05-18 15:02:41 · 224 阅读 · 0 评论 -
66. Plus One
class Solution {public: vector plusOne(vector& digits) { int len = digits.size(); int plus = 0; for(int i = len - 1 ; i >=0 ;i--){ if(i == len - 1){原创 2017-05-10 10:47:47 · 206 阅读 · 0 评论 -
152. Maximum Product Subarray
分析法案:点击打开链接最小的负数乘以负数是可以变成最大的乘积,因为是可以当个值成为一个字串的所以有和单个值的比较。有两个乘积记录子序列的乘积,从最大的正值和最小的负值去记录更新。class Solution {public: int maxProduct(vector& nums) { int re; if(nums.empty()){原创 2017-06-14 15:59:19 · 269 阅读 · 0 评论 -
151. Reverse Words in a String
reverse讲解,size与capcity区别:点击打开链接参考代码解释:点击打开链接我的实现:class Solution {public: void reverseWords(string &s) { //利用reverse函数事半功倍 //string类型是可以用s[]这样来访问元素的 //storeIndex表示当前存原创 2017-06-14 10:41:16 · 320 阅读 · 0 评论 -
520. Detect Capital
class Solution {public: bool detectCapitalUse(string word) { int len = word.size(); if(len<=0){ return false; } if(len == 1){ return true;原创 2017-07-10 16:49:29 · 359 阅读 · 0 评论 -
112. Path Sum
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas原创 2017-05-22 13:10:29 · 256 阅读 · 0 评论 -
119. Pascal's Triangle II
class Solution {public: vector getRow(int rowIndex) { vector res; if(rowIndex==0){ res.push_back(1); return res; } vector pre ; pre原创 2017-05-22 10:23:19 · 230 阅读 · 0 评论 -
118. Pascal's Triangle
class Solution {public: vector> generate(int numRows) { vector> res; if(numRows == 0) return res; if(numRows == 1) return {{1}}; for(int j = 0 ; j < numRows ; j+原创 2017-05-21 22:26:51 · 239 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
参考:(1)点击打开链接class Solution {public: int maxProfit(vector& prices) { int len = prices.size(); //为了第一次买操作的不取prebuy,buy取系统最小值,这样就是之前卖的总值减去当前价格就是这次买的手里的价格 int prebuy = 0原创 2017-05-19 16:15:26 · 382 阅读 · 0 评论 -
123. Best Time to Buy and Sell Stock III
参考了:(1)点击打开链接(2)点击打开链接class Solution {public: int maxProfit(vector& prices) { if(prices.size() == 0){ return 0; } int g[3] = {0} , l[3] = {0}; //原创 2017-05-19 10:07:37 · 223 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
class Solution {public: int mySqrt(int x) { double cur = x,pre =0; while(abs(pre-cur)>0.000001){ pre = cur; cur = pre/2 + (x/(2*pre)); } r原创 2017-05-10 16:55:39 · 210 阅读 · 0 评论 -
LeetCode 213:House Robber II
class Solution {public: int rob(vector& nums) { int length = nums.size(); //cout << "length = " << length << endl; int dp[10000] = {0}; int max1 = 0; int max2 = 0; if (length == 0){ r原创 2017-04-27 22:54:57 · 267 阅读 · 0 评论 -
Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* me原创 2017-04-24 16:01:40 · 273 阅读 · 0 评论 -
Valid Parentheses
#include#include#includeusing namespace std;class Solution {public: bool isValid(string s) { int length = s.size(); int i = 1; stack temp; if (length == 0){ return false; } temp.原创 2017-04-24 15:08:18 · 276 阅读 · 0 评论 -
Leetcode StringToInteger 8
//算法思想:对于一个输入串来说,//step1:首先判断是不是空格,是空格的话就顺序找下去直到第一个非空格的字符//step2:对于第一个非空格的字符来说,判断是不是字母,是字母的话此字符串不能转化为数字(⊙o⊙)哦!//step3: 如果是行结束符的话,就结束啦!//step3:判断第一个字符是不是正负号,并做标记//step4: 判断是不是溢出这里根据别人的代码表示超过2的31次方原创 2016-10-25 10:16:19 · 440 阅读 · 0 评论 -
leetcode zigzag C++ 争取每日一题,我还是太天真了/(ㄒoㄒ)/~~
#include#include#include//要加上命名空间,否则会报错stringusing namespace std;//我也是个白痴,C++要把类声明什么的放在前面,我认为是因为顺序编译吧!不这么放会报错的!!//以后我会把类声明放前面的class Solution {public: string convert(string s, int numRows)原创 2016-10-13 22:38:07 · 783 阅读 · 0 评论 -
codeblocks 安装注意
codeblocks有的不带有MinGW,需要自行安装。1.首先去下载对应的32位或者64位的MinGW。2.解压即可没有什么安装,记得文件位置。3.改变环境变量的Path,路径是刚才的MinGW下bin文件位置。记得在cmd里测试一下gcc -v用这个命令。4.然后下载codeblocks,在settins里边的compiler settings里边找到tool ...什么的,然原创 2016-08-14 20:59:18 · 474 阅读 · 0 评论 -
计蒜客 数据结构 栈 模板倒水问题
//单调递减栈//题目://我们来看看这样一道题:地上从左到右竖立着 n 块木板,从 1 到 n 依次编号,(10,5,8,12,6)//如下图所示。我们知道每块木板的高度,在第 n 块木板右侧竖立着一块高度无限大的木板,//现对每块木板依次做如下的操作:对于第 i 块木板,我们从其右侧开始倒水,//直到水的高度等于第 i 块木板的高度,倒入的水会淹没 ai 块木板(如果木板左右两侧水的原创 2016-08-12 15:20:26 · 810 阅读 · 0 评论 -
计蒜客 数据结构 栈 数列翻转
//数据结构 栈 数列翻转#include#include#includeusing namespace std;template class Stack {private: Type *urls; int max_size, top_index;public: Stack(int length_input) { urls = new Type原创 2016-08-11 22:08:19 · 481 阅读 · 0 评论 -
计蒜客 数据结构 栈 stack_expression C++
//stack_expression//只处理加法和乘法的用栈实现的表达式求值,表达式长度为n//表达式输入的中间不能有空格#include#include#includeusing namespace std;template class Stack {private: Type *urls; int max_size, top_index;public:原创 2016-08-11 22:01:33 · 753 阅读 · 2 评论 -
计蒜客 数据结构 链表 ——应用筛选简历 C++
//这个程序是,没有头节点的//2016/08/10#includeusing namespace std;class Node {public: int data; Node* next; Node(int _data) { data = _data; next = NULL; }};class LinkList {原创 2016-08-11 17:20:24 · 743 阅读 · 0 评论 -
计蒜客 数据结构 顺序表 C++
#include #include using namespace std;class Vector {private: int size, length; int *data;public: Vector(int input_size) { size = input_size; length = 0; data =原创 2016-08-11 17:18:00 · 747 阅读 · 0 评论 -
计蒜客 数据结构 链表——约瑟夫环 C++
#includeusing namespace std;class Node {public: int data; Node* next; Node(int _data) { data = _data; next = NULL; }};class LinkList {private: Node* head;pub原创 2016-08-11 17:11:20 · 854 阅读 · 0 评论 -
计蒜客 数据结构 队列——循环队列 C++
//循环队列的操作#include #include using namespace std;class Queue {private: int *data; int head, tail, length, count;public: Queue(int length_input) { data = new int[length_input];原创 2016-08-11 17:13:59 · 377 阅读 · 0 评论 -
Leetcode Parlindrome Number 9
//解题思路,回文数就是1234321//分别提取最高位和最低位的数进行比较#include using namespace std;////这个处理不了溢出//class Solution{//public:// bool isParlindrome(int x){// int nTen = 1;// int high = 0;//原创 2016-10-25 14:43:04 · 442 阅读 · 0 评论 -
Reverse Integer Leetcode 每日一题 ↖(^ω^)↗
#include#include#include#define INT_MAX 0x7fffffffusing namespace std;class Solution {public: int reverse(int x) { //主要的是考慮溢出,一開始想用堆棧做但是是不對的,得先把各个数位分开啊!这个是关键 //接着,得考虑变换后是否会超越边界原创 2016-10-14 14:32:28 · 756 阅读 · 0 评论 -
华为20170317实习机试答案
五福#include#include//集齐五福多少套//给出0 1 序列using namespace std;int fu(string &str){ //cout << str << endl; int matrix[6]={0}; //int people_num = 1; int fu_num = 1; for (auto i : str){ if (i ==原创 2017-03-18 17:18:17 · 1523 阅读 · 0 评论 -
LeetCode 64. Minimum Path Sum
class Solution {public: int minPathSum(vector>& grid) { int rows = grid.size(); int columns = grid[0].size(); int res = 0; int dp[1000][1000]={0}; if(rows原创 2017-05-05 14:36:13 · 222 阅读 · 0 评论
分享