- 博客(10)
- 资源 (2)
- 收藏
- 关注
原创 leetcode笔记—求最长有效匹配括号子串的长度
class Solution {public: int longestValidParentheses(string s) { stack t; int maxlen=0,last=-1; for(int i=0;i<s.size();i++) { if(s[i]=='(') {
2016-05-30 21:25:57 804
转载 c++高效
C++高效编程忠告这是对C++高效编程的一个总结, 很有指导作用.一、#include “filename.h”和#include 的区别#include “filename.h”是指编译器将从当前工作目录上开始查找此文件#include 是指编译器将从标准库目录中开始查找此文件二、头文件的作用加强安全检测通过头文件可能方便地调用库功能,而不必关心其实现方式
2016-05-29 11:00:39 371
原创 leetcode笔记—生成最大的 数组Create Maximum Number
给定两给数组,从中选取K个使这K个在原始数组中的顺序不变,使数组最大思路:涉及到三个函数:1.取数组中k个最大的元素,顺序不变; 2.合并两个数组,顺序不变,使最大; 3.比较两个数组的大小;class So
2016-05-25 20:51:44 459
原创 leetcode笔记—关于动态规划
1.Integer Breakclass Solution {public: int integerBreak(int n) { if(n==2) return 1; if(n==3) return 2; vector Dp(n+1,0); Dp[0] = 1;Dp[1] = 1;
2016-05-24 21:04:11 306
原创 leetcode笔记—map容器的使用
Given [1,1,1,2,2,3] and k = 2, return [1,2].用一个map容器记下每个元素出现的次数,再用优先级队列按从大到小存下Map的元素class Solution { typedef pair data;public: vector topKFrequent(vector& nums, int k) { map map
2016-05-19 20:49:11 773
原创 leetcode笔记—Substring with Concatenation of All Words加最小的窗户子串
题意:给定一个字符串S和一个字符串数组L,L中的字符串长度都相等,找出S中所有的子串恰好包含L中所有字符各一次,返回子串的起始位置。class Solution {public: vector findSubstring(string s, vector& words) { if(words.size() == 0) return vector(); //w
2016-05-17 21:50:30 347
原创 leetcode笔记—容纳最多水的容器
要找到条纵线然后这两条线以及X轴构成的容器能容纳最多的水。思路:找到最大的 C = min( ai , aj ) * ( j- i) ;一、从前往后遍历,每一个元素与后面所有元素进行比较,这种方法时间复杂度O(n*n),不能接受int n=height.size(); int max=0; for(int i=0;i<n-1;i++)
2016-05-16 22:03:44 405
原创 leetcode笔记—Reorder List
给一个链表 L: L0→L1→…→Ln-1→Ln,需要返回: L0→Ln→L1→Ln-1→L2→Ln-2→…思路1:void reorderList(ListNode* head) { ListNode* p=head; while(p&&p->next) { ListNode* pnext=p->next; /
2016-05-11 10:37:47 953
原创 leetcode笔记—翻转链表
1、翻转链表 void reverseNodes(ListNode *start, ListNode *end) { //翻转链表 ListNode *second = start -> next; ListNode *first = start; ListNode *temp; while(second != end) {
2016-05-05 09:17:52 590
原创 leetcode笔记—Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,
2016-05-02 19:59:28 287
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人