- 博客(5)
- 资源 (1)
- 收藏
- 关注
原创 I/O Stream
文件输入流的变量是ifstream,输出流是ofstream,它们包含在头文件中。stream变量必须通过open函数连接文件。一旦声明了输入/输出流并连接了文件,就可以用">>"/"每一个input-file stream都有成员函数eof来判断是否已读到文件结尾,当程序试图访问文件结尾后的一个字符时才会返回true(即遇到end-of-file标记时)#include...if
2016-02-25 11:47:54 430
原创 Hard题目总结
Binary SearchSearch in Rotated Sorted Array:https://leetcode.com/problems/search-in-rotated-sorted-array/两种方法:1)直接binary search,先判断mid在哪一段,然后判断mid和target的关系,如果结果可能在两段,再判断这段边界(left或right)和target
2016-02-16 00:03:35 1064
原创 Medium题目总结
方法技巧题:search a 2D matrix II:https://leetcode.com/problems/search-a-2d-matrix-ii/从左下角开始,如果元素大于target则行减1,如果小于target则列加1product of array except self: https://leetcode.com/problems/product-of-
2016-02-15 05:10:20 1129
原创 Exception Handling
int amount;try { cin >> amount; if(amount < 0) throw amount;}catch(int e) { cout << amount << " is negative\n";}C++中,基本的异常处理是try-throw-catch。try block中包含想要尝试执行的语句。上例中throw divisor;中的amount有时被
2016-02-14 12:07:00 601
原创 快速排序
该快速排序算法出自《算法导论》思想是,先利用一个partition函数将数组中大于pivot的元素放到右边,小于等于pivot的元素放到左边,然后用pivot将两个部分分割,返回pivot的位置p,再对子数组[start, p - 1]和[p + 1, end]进行排序即可。代码如下:void quickSort(vector& nums, int start, int end) { i
2016-02-06 05:02:49 262
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人