c++
文章平均质量分 54
-缘故-
这个作者很懒,什么都没留下…
展开
-
LeetCode 4.1.3 Largest Rectangle in Histogram
4.1.3 Largest Rectangle in Histogram描述Givenn non-negative integers representing the histogram’s bar height where the width of each bar is1, find the area of largest rectangle in the histogram.原创 2016-04-18 17:18:15 · 354 阅读 · 0 评论 -
num的n次方 O(log(n))
int power(int a, int e){ int res=1; while(e){ if(e&1){ res = res*a; } e>>=1; a = a*a; } return res;}原创 2017-09-05 12:39:24 · 442 阅读 · 0 评论 -
c++ STL 笔记
char 转 stringstringstream ss;ss<<ch;string tmp;ss>>tmp;string str(1,'c'); string大小写转化transform(strA.begin(), strA.end(), strA.begin(), ::toupper); transform(strA.begin(), strA.end(), strA.begi原创 2017-09-06 10:17:58 · 228 阅读 · 0 评论 -
c++ 内存强制释放
malloc_trim(0);原创 2019-01-02 10:22:05 · 2732 阅读 · 0 评论 -
c++ regex 替换
#include &lt;iostream&gt;#include &lt;regex&gt;#include &lt;string&gt;void set_args(string &amp; text, const string&amp; key, const string&amp; value, bool add_args=true) {原创 2019-01-02 10:22:34 · 431 阅读 · 0 评论 -
c++ git上的log库使用
//https://github.com/q191201771/starry-night/tree/master/src/base/*chef_log.ccchef_log.h*/bool debuglog; chef::log::init(debuglog ? chef::log::mode::mode_debug : chef::log::mode::mode_re...原创 2019-01-02 10:22:43 · 243 阅读 · 0 评论 -
c++ git上的task thread库 使用
//https://github.com/q191201771/starry-night/tree/master/src/base/*chef_env.hppchef_noncopyable.hppchef_task_thread.ccchef_task_thread.hchef_wait_event_counter.ccchef_wait_event_counter.h*/t...原创 2019-01-02 10:23:01 · 421 阅读 · 0 评论 -
c++ 文件操作的 单例模式 范例
//.h#include &lt;stdint.h&gt;#include &lt;fstream&gt;#include &lt;mutex&gt;class File { public: static File &amp;instance(); void write(const std::string &amp;str); p原创 2019-01-03 15:12:55 · 422 阅读 · 0 评论 -
c++ rapidjson库的使用
//rapijson#include &lt;rapidjson/document.h&gt;#include &lt;rapidjson/istreamwrapper.h&gt;#include "rapidjson/error/en.h"#include &lt;fstream&gt;#define has_uint(val, key) (原创 2019-01-03 15:12:47 · 1094 阅读 · 0 评论 -
Uber面试题2 | House Robber III
题目描述 小偷找到了一个新的偷盗地点,这里地区的房子组成了一棵二叉树,地区的入口是二叉树的根所在的房子。如果小偷同时偷窃了两个直接相邻的房子,就会触发警报器。求在不触发警报器的情况下小偷可以抢到的最多的money。Example: 3 / \ 2 3 \ \ 3 1小偷可以抢到的最多的money是3+3+1=转载 2016-05-04 16:48:22 · 773 阅读 · 0 评论 -
Uber面试题1 | 房屋窃贼 House Robber II
题目描述 小偷找到了一个新的偷盗地点,这个地区的房子组成了一个环,如果小偷同时偷窃了两个直接相邻的房子,就会触发警报器。在不触发警报器的情况下,求小偷可以抢到的最多的money。解题思路 本题是House Robber的follow up。House Robber-i中房子排列成一个序列,用动态规划就可以动态规划四要素说说dp状态的定义:df[i]表示前i个转载 2016-05-04 16:42:59 · 716 阅读 · 0 评论 -
LeetCode 3.5 Longest Palindromic Substring
3.5 Longest Palindromic Substring描述Given a stringS, find the longest palindromic substring inS. You may assume that the maximumlength ofS is 1000, and there exists one unique longest palindr原创 2016-04-18 15:38:26 · 284 阅读 · 0 评论 -
LeetCode 2.1.24 Single Number II
2.1.24 Single Number II描述Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could yo原创 2016-04-18 13:37:57 · 336 阅读 · 0 评论 -
LeetCode 2.1.21 Gas Station
2.1.21 Gas Station 描述There are N gas stations along a circular route, where the amount of gas at stationi isgas[i].You have a car with an unlimited gas tank and it costscost[i]o原创 2016-04-18 12:17:06 · 306 阅读 · 0 评论 -
LeetCode 2.1.10 4Sum
2.1.10 4Sum描述Given an arrayS ofn integers, are there elementsa, b, c, andd inS such thata +b +c +d =target?Find all unique quadruplets in the array which gives the sum of targe原创 2016-04-18 11:20:09 · 248 阅读 · 0 评论 -
LeetCode 2.1.16 Rotate Image
2.1.16 Rotate Image描述You are given ann ×n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?分析 首先想到,纯模拟,从外到内一圈一圈的转,但这个方法太慢原创 2016-04-18 11:13:59 · 283 阅读 · 0 评论 -
C++ 字典遍历
CCDictElement * pElement; CCDICT_FOREACH(result, pElement) { const char * key = pElement->getStrKey(); CCString * value = (CCString *)pElement->getObject(); CCLog(key);原创 2016-05-10 17:31:06 · 4797 阅读 · 0 评论 -
二叉树遍历 Morris O(1)空间复杂度
本文主要解决一个问题,如何实现二叉树的前中后序遍历,有两个要求:1. O(1)空间复杂度,即只能使用常数空间;2. 二叉树的形状不能被破坏(中间过程允许改变其形状)。通常,实现二叉树的前序(preorder)、中序(inorder)、后序(postorder)遍历有两个常用的方法:一是递归(recursive),二是使用栈实现的迭代版本(stack+iterativ转载 2016-04-18 18:38:45 · 5420 阅读 · 0 评论 -
LeetCode 13.7 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”: great / \ gr原创 2016-05-03 16:01:14 · 350 阅读 · 0 评论 -
C++ BOOST笔记 时间, 指针
时间//当前时钟std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;( std::chrono::steady_clock::now().time_since_epoch()).count() //当前时间戳std::chr...原创 2019-01-03 15:12:38 · 403 阅读 · 0 评论