自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 资源 (2)
  • 收藏
  • 关注

原创 数组的引用于引用数组

http://blog.csdn.net/desilting/article/details/7983530

2015-08-31 21:42:06 468

转载 struct字节对齐

http://blog.chinaunix.net/uid-14802518-id-2784907.html 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特 定的内存地址访问,这就需要各种类型数据按照一定的规则在空间上排列,而不是顺序的一个接一个的排放,这就是对齐。     对齐的作用和原

2015-08-31 10:53:49 433

原创 leetcode 031 Next Permutation

STL里面其实有next_permutation()函数,这个函数实现原理是:在当前序列中,从尾端往前寻找两个相邻元素,前一个记为*i,后一个记为*ii,并且满足*i stl源码如下: template bool next_permutation( BidirectionalIterator first, BidirectionalIterator last ) {

2015-08-30 21:51:46 328

原创 leetcode 021_merge two list

题目让吧两个链表连接起来,并且要按大小顺序排列好。我用的方法比较复杂,花了24ms ListNode* creat(vector &ivec) { ListNode* newnode; ListNode* head; if (ivec.empty()) return NULL; newnode = new ListNode(ivec[0]); if (newnode == N

2015-08-30 19:33:43 389

原创 leetcode 019_Valid Parentheses

判断括号是否正确; bool isValid(string s) { int j = 0,n = 0; string stack = s; while (n != s.size()) { switch (s[n]) { case '(': stack[j++] = '('; break; case '[': stack[j++] = '['; br

2015-08-30 16:03:24 366

原创 leetcode_019Remove Nth Node From End of List

移除单链表倒数第N个节点。 测试平台是没有头结点的单链表!!!我最开始写的是带头结点的,所以测试不通过。这是弄了两个指针。 ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode* temp = head; int i = 0; while (temp != NULL) { ++i; temp = temp->n

2015-08-29 23:28:49 326

原创 leetcode 4sum

前面已经做了2sum,3sum之类的了,其实这些t-sum都可以归纳为O(n-1 ^ (t-1))复杂度。先排序, vector> fourSum(vector& nums, int target) { vector > result; sort(nums.begin(), nums.end()); for (int i = 0; i < nums.size(); ++i) { f

2015-08-29 21:42:35 283

原创 Leetcode_016 Letter Combinations of a Phone Number

这一题比较简答,但是这么简单的题我都敲了30多分钟,结果还有问题,修改,最后花了1个小时。。。。只能感叹自己水平太渣了,不熟练 class Solution { public: vector letterCombinations(string digits) { vector svec{ " ","", "abc","def","ghi","jkl","mno","pqr

2015-08-29 17:14:52 367

原创 leetcode_3sum closet

和上一篇的类似,也是用O(N^2)的方法,先排序,然后找三个位置加起来与2做差比较绝对值 class Solution { public: int threeSumClosest(vector& nums, int target) { int result = 0, minn = abs(nums[0] + nums[1] + nums[2] - target), temp =

2015-08-29 15:50:24 288

原创 leetcode_015 3sum

首先想到的就是3次for循环,从头找到尾,但是time limite exceeded。 考虑优化一下,可以先排序,然后从头开始,找到其相反数 class Solution { public: vector> threeSum(vector& nums) { if (nums.size() < 3) return {};

2015-08-29 14:53:14 261

原创 leetcode_014_Longest Common Prefix

一定注意要判断vector是否为空,其余没什么好说的 class Solution { public: string longestCommonPrefix(vector& strs) { if (strs.empty()) return ""; for (int i = 0; i < strs[0].size(); ++i) { for (int j = 1; j

2015-08-27 17:16:21 250

原创 010 leetcode Integer to Roman

转换起来还比较麻烦,按照每个位来转化,先从最后面开始。 如果这一位在1~3之间,那么就把这个位的罗马字符添到字符串前面; 如果这一位等于4,那么就把当前罗马字符+这个位前,一位的罗马字符 + 字符串连接起来; 如果这一位在5~8之间,那么就把这个位置前面一位的罗马字符 + 当前罗马字符 + 字符串连接起来; 如果这一位等于9,那么就把当前字符 +前两位字符 +字符串连接起来; 代码如下,

2015-08-25 13:47:11 360

原创 010_leetcode Container With Most Water

我最开始写的O(n^2) 的无法通过,从头遍历到结尾 int maxArea(vector& height) { int size = height.size(); int max = 0; for (int i = 0; i != size; ++i) for (int j = i + 1; j != size; ++j) { int volume = (height[i

2015-08-25 10:54:07 338

原创 leetcode_palindrome number_009

这一题也很简单,用了80ms,ac代码如下。思路就是:把各个位数据的ASCII码存在string中,然后用迭代器和反向迭代器查找对比,迭代一半的长度即可。 bool isPalindrome(int x) { if (x < 0) return false; if(x == 0) return true; string result; int val = x;

2015-08-24 22:16:09 401

原创 LeetCode_reverse integer_007

一次性提交代码运行时间8ms,战胜100%的玩家!!哈哈哈,这一题很简单,但是如果不提前看看spoiler的话还是容易考虑不全。 注意两点即可,123000转化后前面的0要去掉;不能超出整形数据的最大范围。 最开始我不太清楚整形数据范围就自己计算。 int max = ~(unsigned int)0 / 2);//计算最大数int min = -max - 1;//最小数 其实在limi

2015-08-24 16:56:42 387

原创 LeetCode_ZigZag Conversion_006

这一题不难,但是我因为没有加上特殊条件检测  if( numRows 所以提交很多次都没有通过,真的是细节决定AC啊!!! class Solution{ public: std::string convert(std::string s, int numRows){ int len1 = s.size(); if (numRows <= 1) retur

2015-08-23 14:34:16 364

原创 LeetCode - Longest SubString without repeating characters_003

首先用了时间复杂度为O(n^2)的方法,耗时比较长,花了216ms(好忧伤,自己首先想到的方法总是很耗时间。。。。) class Solution { public: int lengthOfLongestSubstring(string s) { vector ivec; for (int i = 0; i != s.size(); ++i) { string

2015-08-22 13:17:24 285

原创 LeetCode-Add Two Numbers_002

最容易想到的就是把链表里面的数取出来按倒序组成数,然后两个链表中的数字相加得到一个新数 再把这个数拆开放到链表里面。 注意要用long 型,用int 型会溢出。这个方法如果输入的数字再多一点就没法求了,毕竟long型也是有限的。运行了40ms ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *result,*

2015-08-21 21:45:01 540

原创 分苹果问题

使用递归来做比较好, #include using namespace std; int SharingApple(int m, int n) { if(m == 1 || n == 1) return 1; if(m < n) return SharingApple(m , m); else if(m > n) return SharingApple(m, n-1) + SharingAp

2015-08-21 10:49:25 426

转载 leetcode——Two Sum_1

http://blog.csdn.net/jiadebin890724/article/details/23305449 第一次做,没有经验,上来就用暴力求解,结果超时了。 链接中的文章写得不错,可以参考。

2015-08-21 09:59:39 321

蓝牙A2DP库文件使用方法

The A2DP library handles the signalling procedures to perform stream negotiation and establishment as detailed in the Audio/Video Distribution Transport Protocol Specification, Generic Audio/Video Distribution Profile Specification and Advanced Audio Distribution Profile Specification documents.

2013-08-30

CSR8670---如何开发自己的应用程序

This document introduces the fundamental concepts employed when developing applications designed to run on CSR’s BlueCore chips.

2013-08-30

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除