- 博客(27)
- 资源 (1)
- 收藏
- 关注
转载 c++ STL 容器
【转自:http://www.cppblog.com/tankzhouqiang/archive/2011/06/02/147939.html】参考:STL源码分析(一)vector容器vector的数据安排以及操作方式,与array非常相似。两者的唯一区别在于空间的运用的灵活性。array是静态空间,一旦配置了就不能改变。vector是动态空间,随着元素的加入,它的内部机制会自行扩充空间
2015-03-18 14:50:18 592
原创 【LeetCode笔记】Rotate Array
写了两种方法1. 用STL函数void rotate(int num[], int n, int k){ k %= n; if(k == 0) return; reverse(num, num + n); reverse(num, num + k); //[0..k-1] reverse(num + k, num +
2015-03-10 09:38:35 531
原创 【LeetCode笔记】Compare Version Numbers
int compareVersion(string version1, string version2) {stringstream s1(version1), s2(version2);while(1){int i1= 0, i2 = 0;if(getline(s1, version1, '.')) //if读取成功,将字符串convert为整型i1 = stoi(ver
2015-03-09 05:43:25 690
原创 Amazon电面题目-sort 100 IP addresses
第一次面试,有点紧张,犯了许多错误,电面就挂了。回头题目自己写下。不知道对不对。题目:排序100个IP地址,其中可能有非法的IP(例如:192.168.2.1.11 ,192.256.7.1,192.010.2.1)#include#include#include#include#includeusing namespace std;//s1=s2
2015-03-07 06:37:41 837
原创 关于stringstream重复使用时的问题2
string s1("333.444.555"); string s2("666.777.888");stringstream ss;string w1, w2;ss getline(ss, w1, '.');ss >> s1;cout ss.str("");// ss.clear();ss getline(ss, w2, '.');ss
2015-03-07 05:56:19 712
原创 关于stringstream重复使用时的问题
1.clear()与str("")测试代码string s1("333.444.555");string s2("666.777.888");stringstream ss;string w1, w2;ss getline(ss, w1, '.');cout ss.clear(); // ss.str("");ss getline(ss, w
2015-03-07 05:34:38 1314
原创 【LeetCode笔记】String to Integer (atoi)
用了几个Character handling functions,简化了代码。挺实用的。 (ctype.h)Character handling functionsThis header declares a set of functions to classify and transform individual characters.FunctionsThese fun
2015-02-13 12:57:46 481
原创 回溯和DFS的区别
Definition:Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to t
2014-12-22 17:49:40 3714
原创 【LeetCode笔记】Wildcard Matching 和 Regular Expression Matching
这两道题第一眼看上去都差不多,通常思路就是用动态规划做。对于Regular Expression Matching可以50ms通过所有test case; 而对于Wildcard Matching却需要900ms.不知道OJ用了什么不同的test case,但是DP的时间复杂度是M*N的,没道理差别这么大。Dissuss里很多人用DP还不能通过。原因可能如下:boo
2014-12-22 12:12:01 1383
原创 【LeetCode笔记】Merge Intervals
用STL sort重写Compare时发生了一个错误,以前没有注意到的。我第一次写的:struct MyCmp{bool operator()(const Interval a, const Interval b){return (a.start }}mycmp;在运行是得到了Runtime Error。后来把 简单测试了一下:Input:(50,60)
2014-11-30 09:09:13 530
原创 【LeetCode笔记】Regular Expression Matching
Recursive method:bool isMatch(const char *s, const char *p) { //p is empty if(*p == '\0') return (*s == '\0'); //p is not empty //a * is followed if(*(p + 1) == '*'){ //take 0 preceding
2014-10-06 09:30:19 602
原创 【LeetCode笔记】Palindrome Partitioning
2 DP methods are used in this implementation:1. DP method to find all palind
2014-10-04 07:48:23 495
原创 【LeetCode笔记】Longest Palindromic Substring
Implement the Manacher’s algorithm
2014-10-01 06:54:17 589
原创 【LeetCode笔记】Candy
Something wrong with my solution as describing below.I got a wrong answer: Input: [1,2,4,4,3] Output: 10 Expected: 9my output is 1+2+3+3+1 = 10. and I think OJ's is 1+2+3+2+1 = 9how can
2014-08-28 14:40:25 648
转载 【LeetCode笔记】Word Break
Bottom up DPclass Solution {public: bool wordBreak(string s, unordered_setstring> &dict) { int len = s.length(); vectorbool> dp(len + 1,false); dp[len] = true;
2014-08-26 06:19:17 525
原创 【LeetCode笔记】Linked List Cycle
Set a fast runner and a slow runner. The fast runner jumps 2 nodes at one time, and the slow runner jumps 1 nodes at one time.
2014-07-10 03:44:13 544
原创 【LeetCode笔记】Reverse Integer
1. If want to reuse the same stringstream object, need to clear the buffer before use.
2014-07-08 23:44:29 516
转载 c++操作符及其优先级
From greatest to smallest priority, C++ operators are evaluated in the following order:LevelPrecedence groupOperatorDescriptionGrouping1Scope::scope qualifierLeft-to-righ
2014-07-01 09:01:54 695
原创 Android Google Maps开发笔记:【2】如何配置AndroidManifest.xml文件
1.在元素中加入子标签 android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>其中your_api_key置换成自己申请的API Key。2. 中加入一些许可信息 android:name="com.example.mapde
2014-06-28 14:29:27 827
原创 Android Google Maps开发笔记:【4】如何解决添加Google Maps Project无法运行
在AndroidManifest.xml文件中加入 android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
2014-06-28 14:27:02 607
原创 Android Google Maps开发笔记:【3】如何配置emulator正确运行GoogleMaps程序
Android Google Maps开发笔记:3.如何配置emulator正确运行GoogleMaps程序Update the emulator:Download the new files for latest play services:com.google.android.gms_20130908.apkcom.android.vending_2
2014-06-28 14:26:28 635
原创 Android Google Maps开发笔记:【1】如何获取 Google Maps API key
1.获取SHA-1 fingerprint Eclipse中的Windows > Prefs > Android > Build2.获取API Key网址:https://code.google.com/apis/console/ 在左边的导航条中选择API Access。 在出来的页面中选择Create New Android Key
2014-06-28 14:21:33 500
转载 【未名空间】一些oop的概念
The candidate should be able to give satisfactory definitions for a randomselection of the following terms:class, object (and the difference between the two)instantiationmethod (as opposed to,
2014-06-28 14:17:52 704
转载 C++ sizeof用法
C++ sizeof用法.sizeofsizeof操作符的作用是返回一个对象或类型名的长度,长度的单位是字节。返回值的类型是标准库命名为size_t的类型,size_t类型定义在cstddef头文件中,该头文件是C标准库的头文件stddef.h的C++版本。他是一个和机器相关的unsigned类型,其大小足以保证内存中对象的大小。 1、什么是sizeof 首先看一下siz
2014-06-28 14:08:54 615
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人