From 6b742a5393088c4923ea886e83fc053119f3e95c Mon Sep 17 00:00:00 2001 From: huihut Date: Fri, 9 Feb 2018 21:47:58 +0800 Subject: [PATCH] First Update --- .vscode/settings.json | 9 ++ Algorithm/BubbleSort.h | 14 ++ Algorithm/BubbleSort_orderly.h | 18 +++ .../best-time-to-buy-and-sell-stock.h | 14 ++ .../container-with-most-water.h | 22 +++ Problems/LeetcodeProblems/majority-element.h | 26 +++ Problems/LeetcodeProblems/maximum-subarray.h | 13 ++ .../median-of-two-sorted-arrays.h | 0 Problems/LeetcodeProblems/move-zeroes.h | 12 ++ Problems/LeetcodeProblems/two-sum.h | 18 +++ README.md | 152 ++++++++++++++++++ 11 files changed, 298 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Algorithm/BubbleSort.h create mode 100644 Algorithm/BubbleSort_orderly.h create mode 100644 Problems/LeetcodeProblems/best-time-to-buy-and-sell-stock.h create mode 100644 Problems/LeetcodeProblems/container-with-most-water.h create mode 100644 Problems/LeetcodeProblems/majority-element.h create mode 100644 Problems/LeetcodeProblems/maximum-subarray.h create mode 100644 Problems/LeetcodeProblems/median-of-two-sorted-arrays.h create mode 100644 Problems/LeetcodeProblems/move-zeroes.h create mode 100644 Problems/LeetcodeProblems/two-sum.h create mode 100644 README.md diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..30c1c8e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "files.associations": { + "initializer_list": "cpp", + "type_traits": "cpp", + "xstring": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/Algorithm/BubbleSort.h b/Algorithm/BubbleSort.h new file mode 100644 index 0000000..f899db6 --- /dev/null +++ b/Algorithm/BubbleSort.h @@ -0,0 +1,14 @@ +// 冒泡排序 + +void BubbleSort(vector& v) { + int temp; + for (int i = 0; i < v.size() - 1; ++i) { + for (int j = 0; j < v.size() - 1 - i; ++j) { + if (v[j] > v[j + 1]) { // 从小到大 + temp = v[j]; + v[j] = v[j + 1]; + v[j + 1] = temp; + } + } + } +} \ No newline at end of file diff --git a/Algorithm/BubbleSort_orderly.h b/Algorithm/BubbleSort_orderly.h new file mode 100644 index 0000000..9ecdbb2 --- /dev/null +++ b/Algorithm/BubbleSort_orderly.h @@ -0,0 +1,18 @@ +// 冒泡排序(跳过有序的改进版) + +void BubbleSort_orderly(vector& v) { + int temp; + bool orderly = false; + for (int i = 0; i < v.size() - 1 && !orderly; ++i) { + orderly = true; + for (int j = 0; j < v.size() - 1 - i; ++j) { + if (v[j] > v[j + 1]) + { + orderly = false; + temp = v[j]; + v[j] = v[j + 1]; + v[j + 1] = temp; + } + } + } +} \ No newline at end of file diff --git a/Problems/LeetcodeProblems/best-time-to-buy-and-sell-stock.h b/Problems/LeetcodeProblems/best-time-to-buy-and-sell-stock.h new file mode 100644 index 0000000..fef96f9 --- /dev/null +++ b/Problems/LeetcodeProblems/best-time-to-buy-and-sell-stock.h @@ -0,0 +1,14 @@ +class Solution { +public: + int maxProfit(vector& prices) { + int left = 0, right = 0; + int max = 0, temp = 0; + for(auto i = 0; i < prices.size(); ++i) { + right = i; + temp = prices[right] - prices[left]; + if(temp < 0) left = i; + if(max < temp) max = temp; + } + return max; + } +}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/container-with-most-water.h b/Problems/LeetcodeProblems/container-with-most-water.h new file mode 100644 index 0000000..54d7f67 --- /dev/null +++ b/Problems/LeetcodeProblems/container-with-most-water.h @@ -0,0 +1,22 @@ +class Solution { +public: + int maxArea(vector& height) { + int left = 0, right = height.size()-1; + int max = 0, temp = 0; + while(left < right) { + temp = (right - left) * (height[left] < height[right] ? height[left] : height[right]); + if(max < temp) max = temp; + if(height[left] < height[right]) { + do{ + left++; + } while(left < right && height[left-1] >= height[left]); + } + else { + do{ + right--; + } while(left < right && height[right] <= height[right+1]); + } + } + return max; + } +}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/majority-element.h b/Problems/LeetcodeProblems/majority-element.h new file mode 100644 index 0000000..899de42 --- /dev/null +++ b/Problems/LeetcodeProblems/majority-element.h @@ -0,0 +1,26 @@ +#include +class Solution { +public: + int majorityElement(vector& nums) { + int n = nums.size(); + map m_times; + int moreThanTimes = n / 2; + for (auto i = 0; i < n; ++i) { + auto it = m_times.find(nums[i]); + if (it == m_times.end()) { + // No existence in map, insert + m_times.insert(std::pair(nums[i], 1)); + it = m_times.find(nums[i]); + } + // Is it more than ⌊ n/2 ⌋ times ? + if ((*it).second > moreThanTimes) { + return (*it).first; + } + else { + (*it).second++; + } + } + // Can't find + return -1; + } +}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/maximum-subarray.h b/Problems/LeetcodeProblems/maximum-subarray.h new file mode 100644 index 0000000..c117cf4 --- /dev/null +++ b/Problems/LeetcodeProblems/maximum-subarray.h @@ -0,0 +1,13 @@ +#define MIN_INT -2147483648 +class Solution { +public: + int maxSubArray(vector& nums) { + int max = MIN_INT, temp = 0; + for(auto i = 0; i < nums.size(); ++i) { + temp += nums[i]; + if(temp > max) max = temp; + if(temp < 0) temp = 0; + } + return max; + } +}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/median-of-two-sorted-arrays.h b/Problems/LeetcodeProblems/median-of-two-sorted-arrays.h new file mode 100644 index 0000000..e69de29 diff --git a/Problems/LeetcodeProblems/move-zeroes.h b/Problems/LeetcodeProblems/move-zeroes.h new file mode 100644 index 0000000..19059f1 --- /dev/null +++ b/Problems/LeetcodeProblems/move-zeroes.h @@ -0,0 +1,12 @@ +class Solution { +public: + void moveZeroes(vector& nums) { + int left = 0, right = 0; + for(; left < nums.size() && nums[left] != 0; left++); + for(right = left; right < nums.size(); right++) { + if(nums[right] == 0) continue; + nums[left++] = nums[right]; + } + while(left < nums.size()) nums[left++] = 0; + } +}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/two-sum.h b/Problems/LeetcodeProblems/two-sum.h new file mode 100644 index 0000000..4bfcb23 --- /dev/null +++ b/Problems/LeetcodeProblems/two-sum.h @@ -0,0 +1,18 @@ +class Solution { +public: + vector twoSum(vector& nums, int target) { + vector sum; + for(auto i = 0; i < nums.size(); i++) + { + for(auto j = i+1; j < nums.size(); j++) + { + if(i == j) continue; + if(nums[i] + nums[j] != target) continue; + sum.push_back(i); + sum.push_back(j); + return sum; + } + } + return sum; + } +}; \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..af50b4e --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ + +## 目录 + +* [C/C++](#) +* [STL](#) +* [数据结构](#) +* [算法](#) +* [Problems](#) +* [操作系统](#) +* [计算机网络](#) +* [数据库](#) +* [设计模式](#) +* [网络编程](#) +* [海量数据处理](#) +* [其他](#) +* [书籍](#) +* [复习刷题网站](##) +* [面试题目经验](##) + +---- + +## C/C++ + +* 封装 +* 继承 +* 多态 +* 虚函数 +* 内存分配和管理 +* extern"C" +* const作用 +* 什么是面向对象(OOP) +* new和malloc的区别 +* 运行时类型识别(RTTI) +* 友元类和友元函数 +* struct和class的区别 + +## STL + +## 数据结构 + +## 算法 + +### 排序 + +* [冒泡排序](Algorithm/BubbleSort.h) +* [冒泡排序(跳过有序的改进版)](Algorithm/BubbleSort_orderly.h) + +## Problems + +### Leetcode Problems + +#### Array + +* [1. Two Sum](Problems/LeetcodeProblems/two-sum.h) +* [4. Median of Two Sorted Arrays](Problems/LeetcodeProblems/median-of-two-sorted-arrays.h) +* [11. Container With Most Water](Problems/LeetcodeProblems/container-with-most-water.h) +* [53. Maximum Subarray](Problems/LeetcodeProblems/maximum-subarray.h) +* [121. Best Time to Buy and Sell Stock](Problems/LeetcodeProblems/best-time-to-buy-and-sell-stock.h) +* [169. Majority Element](Problems/LeetcodeProblems/majority-element.h) +* [283. Move Zeroes](Problems/LeetcodeProblems/move-zeroes.h) + + +## 操作系统 + +* 进程间的通信方式(管道、有名管道、信号、共享内存、消息队列、信号量、套接字、文件) + +## 计算机网络 + +* TCP/IP +* TCP协议 +* TCP三次握手 +* TCP和UDP的区别 +* socket套接字 +* HTTP返回码 + +### HTTP + +[runoob . HTTP教程](http://www.runoob.com/http/http-tutorial.html) + +#### HTTP 请求方法 +* GET:请求指定的页面信息,并返回实体主体 +* HEAD:类似于get请求,只不过返回的响应中没有具体的内容,用于获取报头 +* POST:向指定资源提交数据进行处理请求(例如提交表单或者上传文件)。数据被包含在请求体中。POST请求可能会导致新的资源的建立和/或已有资源的修改。 +* PUT:从客户端向服务器传送的数据取代指定的文档的内容。 +* DELETE:请求服务器删除指定的页面 +* CONNECT:HTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器 +* OPTIONS:允许客户端查看服务器的性能 +* TRACE:回显服务器收到的请求,主要用于测试或诊断 + +#### HTTP 状态码 +* 200 OK: 请求成功 +* 301 Moved Permanently: 永久移动。请求的资源已被永久的移动到新URI,返回信息会包括新的URI,浏览器会自动定向到新URI。今后任何新的请求都应使用新的URI代替 +* 400 Bad Request: 客户端请求的语法错误,服务器无法理解 +* 401 Unauthorized: 请求要求用户的身份认证 +* 403 Forbidden: 服务器理解请求客户端的请求,但是拒绝执行此请求 +* 404 Not Found: 服务器无法根据客户端的请求找到资源(网页)。通过此代码,网站设计人员可设置"您所请求的资源无法找到"的个性页面 +* 408 Request Timeout: 服务器等待客户端发送的请求时间过长,超时 +* 500 Internal Server Error: 服务器内部错误,无法完成请求 +* 503 Service Unavailable: 由于超载或系统维护,服务器暂时的无法处理客户端的请求。延时的长度可包含在服务器的Retry-After头信息中 +* 504 Gateway Timeout: 充当网关或代理的服务器,未及时从远端服务器获取请求 + +## 数据库 + +* 数据库事务四大特性:原子性、一致性、分离性、持久性 +* 数据库索引:顺序索引 B+树索引 hash索引 +[MySQL索引背后的数据结构及算法原理](http://blog.codinglabs.org/articles/theory-of-mysql-index.html) + +## 设计模式 + +## 网络编程 + +## 海量数据处理 + +* [ 海量数据处理面试题集锦](http://blog.csdn.net/v_july_v/article/details/6685962) +* [十道海量数据处理面试题与十个方法大总结](http://blog.csdn.net/v_JULY_v/article/details/6279498) + +## 其他 + +---- + +## 书籍 + +* 《剑指Offer》 +* 《编程珠玑》 +* 《深度探索C++对象模型》 +* 《Effective C++》 +* 《More Effective C++》 +* 《深入理解C++11》 +* 《STL源码剖析》 +* 《深入理解计算机系统》 +* 《TCP/IP网络编程》 +* 《程序员的自我修养》 + +## 复习刷题网站 + +* [leetcode](https://leetcode.com/) +* [牛客网](https://www.nowcoder.net/) +* [慕课网](https://www.imooc.com/) +* [菜鸟教程](http://www.runoob.com/) + +## 面试题目经验 + +* [知乎 . 互联网公司最常见的面试算法题有哪些?](https://www.zhihu.com/question/24964987) +* [知乎 . 面试 C++ 程序员,什么样的问题是好问题?](https://www.zhihu.com/question/20184857) +* [cnblogs . C++面试集锦( 面试被问到的问题 )](https://www.cnblogs.com/Y1Focus/p/6707121.html) +* [cnblogs . C/C++ 笔试、面试题目大汇总](https://www.cnblogs.com/fangyukuan/archive/2010/09/18/1829871.html) +* [cnblogs . 常见C++面试题及基本知识点总结(一)](https://www.cnblogs.com/LUO77/p/5771237.html) +* [CSDN . 全面整理的C++面试题](http://blog.csdn.net/ljzcome/article/details/574158) +* [CSDN . 百度研发类面试题(C++方向)](http://blog.csdn.net/Xiongchao99/article/details/74524807?locationNum=6&fps=1) +* [CSDN . c++常见面试题30道](http://blog.csdn.net/fakine/article/details/51321544) +* [CSDN . 腾讯2016实习生面试经验(已经拿到offer)](http://blog.csdn.net/onever_say_love/article/details/51223886) +* [segmentfault . C++常见面试问题总结](https://segmentfault.com/a/1190000003745529) \ No newline at end of file