├── template
├── out.txt
├── in.txt
├── template.cpp
├── oj.c
└── oj.cpp
├── 026-复杂链表的复制
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── map.cpp
├── linknext.cpp
└── bruteforce.cpp
├── 028-字符串的排列
├── abc.jpg
├── next_permutation.cpp
├── permutation_error.cpp
└── permutation.cpp
├── 031-连续子数组的最大和
├── dp.png
├── 03-sum.cpp
├── 04-sum.cpp
├── 01-bruteforce.cpp
└── 02-dp.cpp
├── 003-二维数组中的查找
├── find.jpg
├── find7.jpg
├── bruteforce.cpp
├── divide-leftdown.cpp
└── divide-rightup.cpp
├── 006-重建二叉树
└── construct.cpp
├── 007-用两个栈实现队列
├── README.md
├── stack2queue.cpp
└── stack2queue.jpg
├── 010-二进制中1的个数
├── bitset.cpp
├── numberof1_1.cpp
├── numberof1_2.cpp
├── numberof1_3.cpp
└── numberof1_4.cpp
├── 011-数值的整数次方
├── power_1.cpp
├── power_2.cpp
├── power_3.cpp
└── power_4.cpp
├── 017-合并两个排序的链表
├── merge.cpp
└── merge1.cpp
├── 019-二叉树的镜像
├── mirror.jpg
├── mirror_in.cpp
├── mirror_pre.cpp
├── mirror_re.cpp
└── mirror_post.cpp
├── 021-包含min函数的栈
├── README.md
└── stack.cpp
├── 023-从上往下打印二叉树
├── README.md
└── levelorder.cpp
├── 030-最小的K个数
├── 01-sort.cpp
├── 02-heap.cpp
├── 03-partition.cpp
└── 04-multiset.cpp
├── 034-丑数
├── 02-uglynum.cpp
├── 01-bruteforce.cpp
└── 02-uglynum_set.cpp
├── 041-和为S的连续正数序列
└── find.cpp
├── 058-二叉树的下一个结点
└── bst.png
├── 064-数据流之中的中位数
├── multiset
└── multiset.cpp
├── 004-替换空格
├── replacespace.cpp
└── replacespace2.cpp
├── 009-斐波那契数列
├── jumpFloor.cpp
├── rectCover.cpp
├── fibonacci_1.cpp
├── fibonacci_2.cpp
├── jumpFloorII-2.cpp
├── jumpFloorII-3.cpp
├── jumpFloorII.cpp
└── fibonacci_logn.cpp
├── 016-反转链表
├── reverselist1.cpp
└── reverselist2.cpp
├── 018-树的子结构
└── hassubtree.cpp
├── 024-二叉搜索树的后序遍历序列
├── tree.jpg
├── ispost_max
├── ispost_n.cpp
├── ispost_n2.cpp
├── ispost_re.cpp
├── ispost_max.cpp
└── bruteforce.cpp
├── 033-把数组排成最小的数
└── minnum.cpp
├── 039-二叉树的深度
└── treedepth.cpp
├── 048-不能被继承的类
├── friend_class
├── static_func.cpp
├── friend_fun.cpp
├── friend_class.cpp
├── final.cpp
└── static_value.cpp
├── 005-从尾到头打印链表
├── print_stack.cpp
├── print_recursion.cpp
└── print_recursion2.cpp
├── 008-旋转数组的最小数字
├── minnumber.cpp
├── minnumber-On1.cpp
└── minnumber-On2.cpp
├── 012-打印1到最大的N位数
├── print_string
├── print_string.cpp
├── print_recursion.cpp
├── print_recursion2.cpp
└── print.cpp
├── 015-链表中倒数第k个结点
├── findkth1.cpp
└── findkth2.cpp
├── 020-顺时针打印矩阵
├── printmartix.cpp
└── printmartix2.cpp
├── 022-栈的压入弹出序列
├── ispoporder1.cpp
├── ispoporder2.cpp
├── ispoporder3.cpp
└── ispoporder4.py
├── 037-两个链表的第一个公共结点
├── 03-map.cpp
├── 01-bruteforce.cpp
├── 02-align_stack.cpp
├── 02-align_length.cpp
└── 02-align_strcat.cpp
├── 014-调整数组顺序使奇数位于偶数前面
├── buttle.cpp
├── otherarray.cpp
└── reOrderArray.cpp
├── 027-二叉搜索树与双向链表
├── convert_re.cpp
├── convert_re2.cpp
├── convert_stack.cpp
└── convert_re_static_error.cpp
├── 035-第一个只出现一次的字符位置
├── 03-count.cpp
├── 02-bitmap.cpp
└── 01-bruteforce.cpp
├── 046-求1+2+3+...+n
├── bitmulti.cpp
├── pointerofarray.c
├── functemplate.cpp
├── recursion.cpp
├── macro.cpp
├── funcpoint.cpp
├── virtualfunc.cpp
└── constructor.cpp
├── 029-数组中出现次数超过一半的数字
├── 01-halfnum.cpp
├── 02-partition.cpp
├── 03-holdfield.cpp
├── 04-stlcount.cpp
└── 05-map.cpp
├── 032-从1到n整数中1出现的次数
├── 02-divide.cpp
├── 02-divide2.cpp
├── 01-bruteforce.cpp
└── 03-num.cpp
├── 025-二叉树中和为某一值的路径
├── findpath_left_arg.cpp
├── findpath_sum_arg.cpp
├── findpath_sum_static.cpp
└── findpath_left_static.cpp
├── 061-按之字形顺序打印二叉树
├── levelorder_deque.cpp
└── levelorder_reverse.cpp
├── ChineseCodingInterviewAppendix-master
├── ArrayConstruction
│ ├── ArrayConstruction.cpp
│ └── ArrayConstruction.vcxproj.filters
├── Utilities
│ ├── Utilities.vcxproj.user
│ ├── list.h
│ ├── BinaryTree.h
│ ├── Utilities.vcxproj.filters
│ ├── BinaryTree.cpp
│ └── list.cpp
├── FirstCharacterInStream
│ ├── FirstCharacterInStream.cpp
│ └── FirstCharacterInStream.vcxproj.filters
├── RegularExpressionsMatching
│ ├── RegularExpressions.cpp
│ └── RegularExpressionsMatching.vcxproj.filters
├── README.md
├── RobotMove
│ ├── RobotMove.vcxproj.filters
│ └── RobotMove.cpp
├── KthNodeInBST
│ └── KthNodeInBST.vcxproj.filters
├── StreamMedian
│ └── StreamMedian.vcxproj.filters
├── NumericStrings
│ ├── NumericStrings.vcxproj.filters
│ └── NumericString.cpp
├── StringPathInMatrix
│ └── StringPathInMatrix.vcxproj.filters
├── DuplicationInArray
│ └── DuplicationInArray.vcxproj.filters
├── NextNodeInBinaryTrees
│ └── NextNodeInBinaryTrees.vcxproj.filters
├── PrintTreesInLines
│ └── PrintTreesInLines.vcxproj.filters
├── EntryNodeInListLoop
│ └── EntryNodeInListLoop.vcxproj.filters
├── MaxInSlidingWindow
│ └── MaxInSlidingWindow.vcxproj.filters
├── PrintTreesInZigzag
│ └── PrintTreesInZigzag.vcxproj.filters
├── SerializeBinaryTrees
│ └── SerializeBinaryTrees.vcxproj.filters
├── DeleteDuplicatedListNode
│ └── DeleteDuplicatedListNode.vcxproj.filters
└── SymmetricalBinaryTree
│ └── SymmetricalBinaryTree.vcxproj.filters
├── 053-正则表达式匹配
├── re.py
├── dfs2.cpp
├── dp.cpp
└── dfs.cpp
├── .gitignore
├── 047-不用加减乘除做加法
├── inline_asm.cpp
└── bit_add.cpp
├── 038-数字在排序数组中出现的次数
├── 03-firstlast_stlbound.cpp
├── 04-multiset.cpp
├── 01-bruteforce.cpp
├── 03-firstlast_recursion.cpp
├── 02-binarysearch.cpp
└── 03-firstlast.cpp
├── 042-左旋转字符串
├── 01-rotate2.cpp
├── 02-reverse2.cpp
├── 02-reverse.cpp
└── 01-rotate.cpp
├── 052-构建乘积数组
├── multiply.cpp
└── README.md
├── 042-翻转单词顺序列
├── 04-reverse_temp.cpp
├── 04-reverse_temp2.cpp
├── 02-reverse_stl.cpp
├── 01-reverse.cpp
└── 03-reverse_stack.cpp
├── 036-数组中的逆序对
├── 01-bruteforce.cpp
├── 03-selectsort.cpp
├── 02-bubblesort.cpp
├── 05-hash.cpp
└── 04-mergedivide.cpp
├── 045-孩子们的游戏(圆圈中最后剩下的数)
├── joseph_recursion.cpp
├── joseph.cpp
└── lastremaining.cpp
├── 041-和为S的两个数字
└── find.cpp
├── 065-滑动窗口的最大值
├── heap1.cpp
├── bruteforce.cpp
├── heap.cpp
├── maxqueue_s.cpp
└── maxqueue.cpp
├── 056-链表中环的入口结点
└── entry2.cpp
├── 055-字符流中第一个不重复的字符
└── count.cpp
├── 062-序列化二叉树
├── string_to_int.cpp
└── int_to_string.cpp
├── 040-数组中只出现一次的数字
├── find2.cpp
└── find.cpp
├── 044-扑克牌顺子
├── continuous_sort.cpp
└── continuous_n.cpp
├── 051-数组中重复的数字
├── flag.cpp
├── addlength.cpp
├── sort.cpp
├── hashset.cpp
├── 0flag.cpp
└── swap.cpp
├── 057-删除链表中重复的结点
├── count.cpp
└── delete.cpp
├── 054-表示数值的字符串
└── isnumeric.cpp
├── 059-对称的二叉树
└── recursion.cpp
├── 063-二叉搜索树的第K个结点
├── recursion.cpp
└── inorder_stack.cpp
├── 049-把字符串转换成整数
└── myatoi.cpp
└── 039-平衡二叉树[附加]
└── isavlrecursion.cpp
/template/out.txt:
--------------------------------------------------------------------------------
1 | 8
2 | 3
3 |
--------------------------------------------------------------------------------
/template/in.txt:
--------------------------------------------------------------------------------
1 | 3 5
2 | 1 2
3 |
4 |
--------------------------------------------------------------------------------
/026-复杂链表的复制/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/1.jpg
--------------------------------------------------------------------------------
/026-复杂链表的复制/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/2.jpg
--------------------------------------------------------------------------------
/026-复杂链表的复制/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/3.jpg
--------------------------------------------------------------------------------
/026-复杂链表的复制/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/4.jpg
--------------------------------------------------------------------------------
/028-字符串的排列/abc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/028-字符串的排列/abc.jpg
--------------------------------------------------------------------------------
/026-复杂链表的复制/map.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/map.cpp
--------------------------------------------------------------------------------
/031-连续子数组的最大和/dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/031-连续子数组的最大和/dp.png
--------------------------------------------------------------------------------
/003-二维数组中的查找/find.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/003-二维数组中的查找/find.jpg
--------------------------------------------------------------------------------
/003-二维数组中的查找/find7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/003-二维数组中的查找/find7.jpg
--------------------------------------------------------------------------------
/006-重建二叉树/construct.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/006-重建二叉树/construct.cpp
--------------------------------------------------------------------------------
/007-用两个栈实现队列/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/007-用两个栈实现队列/README.md
--------------------------------------------------------------------------------
/010-二进制中1的个数/bitset.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/010-二进制中1的个数/bitset.cpp
--------------------------------------------------------------------------------
/011-数值的整数次方/power_1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/011-数值的整数次方/power_1.cpp
--------------------------------------------------------------------------------
/011-数值的整数次方/power_2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/011-数值的整数次方/power_2.cpp
--------------------------------------------------------------------------------
/011-数值的整数次方/power_3.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/011-数值的整数次方/power_3.cpp
--------------------------------------------------------------------------------
/011-数值的整数次方/power_4.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/011-数值的整数次方/power_4.cpp
--------------------------------------------------------------------------------
/017-合并两个排序的链表/merge.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/017-合并两个排序的链表/merge.cpp
--------------------------------------------------------------------------------
/019-二叉树的镜像/mirror.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/019-二叉树的镜像/mirror.jpg
--------------------------------------------------------------------------------
/021-包含min函数的栈/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/021-包含min函数的栈/README.md
--------------------------------------------------------------------------------
/021-包含min函数的栈/stack.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/021-包含min函数的栈/stack.cpp
--------------------------------------------------------------------------------
/023-从上往下打印二叉树/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/023-从上往下打印二叉树/README.md
--------------------------------------------------------------------------------
/030-最小的K个数/01-sort.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/030-最小的K个数/01-sort.cpp
--------------------------------------------------------------------------------
/030-最小的K个数/02-heap.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/030-最小的K个数/02-heap.cpp
--------------------------------------------------------------------------------
/034-丑数/02-uglynum.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/034-丑数/02-uglynum.cpp
--------------------------------------------------------------------------------
/041-和为S的连续正数序列/find.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/041-和为S的连续正数序列/find.cpp
--------------------------------------------------------------------------------
/058-二叉树的下一个结点/bst.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/058-二叉树的下一个结点/bst.png
--------------------------------------------------------------------------------
/064-数据流之中的中位数/multiset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/064-数据流之中的中位数/multiset
--------------------------------------------------------------------------------
/004-替换空格/replacespace.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/004-替换空格/replacespace.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/jumpFloor.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/jumpFloor.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/rectCover.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/rectCover.cpp
--------------------------------------------------------------------------------
/016-反转链表/reverselist1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/016-反转链表/reverselist1.cpp
--------------------------------------------------------------------------------
/016-反转链表/reverselist2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/016-反转链表/reverselist2.cpp
--------------------------------------------------------------------------------
/017-合并两个排序的链表/merge1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/017-合并两个排序的链表/merge1.cpp
--------------------------------------------------------------------------------
/018-树的子结构/hassubtree.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/018-树的子结构/hassubtree.cpp
--------------------------------------------------------------------------------
/019-二叉树的镜像/mirror_in.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/019-二叉树的镜像/mirror_in.cpp
--------------------------------------------------------------------------------
/019-二叉树的镜像/mirror_pre.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/019-二叉树的镜像/mirror_pre.cpp
--------------------------------------------------------------------------------
/019-二叉树的镜像/mirror_re.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/019-二叉树的镜像/mirror_re.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/tree.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/tree.jpg
--------------------------------------------------------------------------------
/026-复杂链表的复制/linknext.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/linknext.cpp
--------------------------------------------------------------------------------
/031-连续子数组的最大和/03-sum.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/031-连续子数组的最大和/03-sum.cpp
--------------------------------------------------------------------------------
/031-连续子数组的最大和/04-sum.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/031-连续子数组的最大和/04-sum.cpp
--------------------------------------------------------------------------------
/033-把数组排成最小的数/minnum.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/033-把数组排成最小的数/minnum.cpp
--------------------------------------------------------------------------------
/034-丑数/01-bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/034-丑数/01-bruteforce.cpp
--------------------------------------------------------------------------------
/034-丑数/02-uglynum_set.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/034-丑数/02-uglynum_set.cpp
--------------------------------------------------------------------------------
/039-二叉树的深度/treedepth.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/039-二叉树的深度/treedepth.cpp
--------------------------------------------------------------------------------
/048-不能被继承的类/friend_class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/048-不能被继承的类/friend_class
--------------------------------------------------------------------------------
/003-二维数组中的查找/bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/003-二维数组中的查找/bruteforce.cpp
--------------------------------------------------------------------------------
/005-从尾到头打印链表/print_stack.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/005-从尾到头打印链表/print_stack.cpp
--------------------------------------------------------------------------------
/007-用两个栈实现队列/stack2queue.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/007-用两个栈实现队列/stack2queue.cpp
--------------------------------------------------------------------------------
/007-用两个栈实现队列/stack2queue.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/007-用两个栈实现队列/stack2queue.jpg
--------------------------------------------------------------------------------
/008-旋转数组的最小数字/minnumber.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/008-旋转数组的最小数字/minnumber.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/fibonacci_1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/fibonacci_1.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/fibonacci_2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/fibonacci_2.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/jumpFloorII-2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/jumpFloorII-2.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/jumpFloorII-3.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/jumpFloorII-3.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/jumpFloorII.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/jumpFloorII.cpp
--------------------------------------------------------------------------------
/010-二进制中1的个数/numberof1_1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/010-二进制中1的个数/numberof1_1.cpp
--------------------------------------------------------------------------------
/010-二进制中1的个数/numberof1_2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/010-二进制中1的个数/numberof1_2.cpp
--------------------------------------------------------------------------------
/010-二进制中1的个数/numberof1_3.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/010-二进制中1的个数/numberof1_3.cpp
--------------------------------------------------------------------------------
/010-二进制中1的个数/numberof1_4.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/010-二进制中1的个数/numberof1_4.cpp
--------------------------------------------------------------------------------
/012-打印1到最大的N位数/print_string:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/012-打印1到最大的N位数/print_string
--------------------------------------------------------------------------------
/015-链表中倒数第k个结点/findkth1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/015-链表中倒数第k个结点/findkth1.cpp
--------------------------------------------------------------------------------
/015-链表中倒数第k个结点/findkth2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/015-链表中倒数第k个结点/findkth2.cpp
--------------------------------------------------------------------------------
/019-二叉树的镜像/mirror_post.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/019-二叉树的镜像/mirror_post.cpp
--------------------------------------------------------------------------------
/020-顺时针打印矩阵/printmartix.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/020-顺时针打印矩阵/printmartix.cpp
--------------------------------------------------------------------------------
/020-顺时针打印矩阵/printmartix2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/020-顺时针打印矩阵/printmartix2.cpp
--------------------------------------------------------------------------------
/022-栈的压入弹出序列/ispoporder1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/022-栈的压入弹出序列/ispoporder1.cpp
--------------------------------------------------------------------------------
/022-栈的压入弹出序列/ispoporder2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/022-栈的压入弹出序列/ispoporder2.cpp
--------------------------------------------------------------------------------
/022-栈的压入弹出序列/ispoporder3.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/022-栈的压入弹出序列/ispoporder3.cpp
--------------------------------------------------------------------------------
/023-从上往下打印二叉树/levelorder.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/023-从上往下打印二叉树/levelorder.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/ispost_max:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/ispost_max
--------------------------------------------------------------------------------
/026-复杂链表的复制/bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/026-复杂链表的复制/bruteforce.cpp
--------------------------------------------------------------------------------
/030-最小的K个数/03-partition.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/030-最小的K个数/03-partition.cpp
--------------------------------------------------------------------------------
/030-最小的K个数/04-multiset.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/030-最小的K个数/04-multiset.cpp
--------------------------------------------------------------------------------
/037-两个链表的第一个公共结点/03-map.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/037-两个链表的第一个公共结点/03-map.cpp
--------------------------------------------------------------------------------
/009-斐波那契数列/fibonacci_logn.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/009-斐波那契数列/fibonacci_logn.cpp
--------------------------------------------------------------------------------
/014-调整数组顺序使奇数位于偶数前面/buttle.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/014-调整数组顺序使奇数位于偶数前面/buttle.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/ispost_n.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/ispost_n.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/ispost_n2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/ispost_n2.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/ispost_re.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/ispost_re.cpp
--------------------------------------------------------------------------------
/027-二叉搜索树与双向链表/convert_re.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/027-二叉搜索树与双向链表/convert_re.cpp
--------------------------------------------------------------------------------
/027-二叉搜索树与双向链表/convert_re2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/027-二叉搜索树与双向链表/convert_re2.cpp
--------------------------------------------------------------------------------
/035-第一个只出现一次的字符位置/03-count.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/035-第一个只出现一次的字符位置/03-count.cpp
--------------------------------------------------------------------------------
/046-求1+2+3+...+n/bitmulti.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/046-求1+2+3+...+n/bitmulti.cpp
--------------------------------------------------------------------------------
/003-二维数组中的查找/divide-leftdown.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/003-二维数组中的查找/divide-leftdown.cpp
--------------------------------------------------------------------------------
/003-二维数组中的查找/divide-rightup.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/003-二维数组中的查找/divide-rightup.cpp
--------------------------------------------------------------------------------
/005-从尾到头打印链表/print_recursion.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/005-从尾到头打印链表/print_recursion.cpp
--------------------------------------------------------------------------------
/005-从尾到头打印链表/print_recursion2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/005-从尾到头打印链表/print_recursion2.cpp
--------------------------------------------------------------------------------
/008-旋转数组的最小数字/minnumber-On1.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/008-旋转数组的最小数字/minnumber-On1.cpp
--------------------------------------------------------------------------------
/008-旋转数组的最小数字/minnumber-On2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/008-旋转数组的最小数字/minnumber-On2.cpp
--------------------------------------------------------------------------------
/012-打印1到最大的N位数/print_string.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/012-打印1到最大的N位数/print_string.cpp
--------------------------------------------------------------------------------
/024-二叉搜索树的后序遍历序列/ispost_max.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/024-二叉搜索树的后序遍历序列/ispost_max.cpp
--------------------------------------------------------------------------------
/027-二叉搜索树与双向链表/convert_stack.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/027-二叉搜索树与双向链表/convert_stack.cpp
--------------------------------------------------------------------------------
/028-字符串的排列/next_permutation.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/028-字符串的排列/next_permutation.cpp
--------------------------------------------------------------------------------
/028-字符串的排列/permutation_error.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/028-字符串的排列/permutation_error.cpp
--------------------------------------------------------------------------------
/029-数组中出现次数超过一半的数字/01-halfnum.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/029-数组中出现次数超过一半的数字/01-halfnum.cpp
--------------------------------------------------------------------------------
/031-连续子数组的最大和/01-bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/031-连续子数组的最大和/01-bruteforce.cpp
--------------------------------------------------------------------------------
/032-从1到n整数中1出现的次数/02-divide.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/032-从1到n整数中1出现的次数/02-divide.cpp
--------------------------------------------------------------------------------
/032-从1到n整数中1出现的次数/02-divide2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/032-从1到n整数中1出现的次数/02-divide2.cpp
--------------------------------------------------------------------------------
/035-第一个只出现一次的字符位置/02-bitmap.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/035-第一个只出现一次的字符位置/02-bitmap.cpp
--------------------------------------------------------------------------------
/012-打印1到最大的N位数/print_recursion.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/012-打印1到最大的N位数/print_recursion.cpp
--------------------------------------------------------------------------------
/012-打印1到最大的N位数/print_recursion2.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/012-打印1到最大的N位数/print_recursion2.cpp
--------------------------------------------------------------------------------
/014-调整数组顺序使奇数位于偶数前面/otherarray.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/014-调整数组顺序使奇数位于偶数前面/otherarray.cpp
--------------------------------------------------------------------------------
/029-数组中出现次数超过一半的数字/02-partition.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/029-数组中出现次数超过一半的数字/02-partition.cpp
--------------------------------------------------------------------------------
/029-数组中出现次数超过一半的数字/03-holdfield.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/029-数组中出现次数超过一半的数字/03-holdfield.cpp
--------------------------------------------------------------------------------
/032-从1到n整数中1出现的次数/01-bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/032-从1到n整数中1出现的次数/01-bruteforce.cpp
--------------------------------------------------------------------------------
/037-两个链表的第一个公共结点/01-bruteforce.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/037-两个链表的第一个公共结点/01-bruteforce.cpp
--------------------------------------------------------------------------------
/037-两个链表的第一个公共结点/02-align_stack.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/037-两个链表的第一个公共结点/02-align_stack.cpp
--------------------------------------------------------------------------------
/014-调整数组顺序使奇数位于偶数前面/reOrderArray.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/014-调整数组顺序使奇数位于偶数前面/reOrderArray.cpp
--------------------------------------------------------------------------------
/025-二叉树中和为某一值的路径/findpath_left_arg.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/025-二叉树中和为某一值的路径/findpath_left_arg.cpp
--------------------------------------------------------------------------------
/025-二叉树中和为某一值的路径/findpath_sum_arg.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/025-二叉树中和为某一值的路径/findpath_sum_arg.cpp
--------------------------------------------------------------------------------
/037-两个链表的第一个公共结点/02-align_length.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/037-两个链表的第一个公共结点/02-align_length.cpp
--------------------------------------------------------------------------------
/037-两个链表的第一个公共结点/02-align_strcat.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/037-两个链表的第一个公共结点/02-align_strcat.cpp
--------------------------------------------------------------------------------
/061-按之字形顺序打印二叉树/levelorder_deque.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/061-按之字形顺序打印二叉树/levelorder_deque.cpp
--------------------------------------------------------------------------------
/025-二叉树中和为某一值的路径/findpath_sum_static.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/025-二叉树中和为某一值的路径/findpath_sum_static.cpp
--------------------------------------------------------------------------------
/025-二叉树中和为某一值的路径/findpath_left_static.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/025-二叉树中和为某一值的路径/findpath_left_static.cpp
--------------------------------------------------------------------------------
/027-二叉搜索树与双向链表/convert_re_static_error.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/027-二叉搜索树与双向链表/convert_re_static_error.cpp
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/ArrayConstruction/ArrayConstruction.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/ChineseCodingInterviewAppendix-master/ArrayConstruction/ArrayConstruction.cpp
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/Utilities/Utilities.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/FirstCharacterInStream/FirstCharacterInStream.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/ChineseCodingInterviewAppendix-master/FirstCharacterInStream/FirstCharacterInStream.cpp
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/RegularExpressionsMatching/RegularExpressions.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesome-interview/CodingInterviews/master/ChineseCodingInterviewAppendix-master/RegularExpressionsMatching/RegularExpressions.cpp
--------------------------------------------------------------------------------
/046-求1+2+3+...+n/pointerofarray.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int rich(int n)
5 | {
6 | return ( (int)( &((uint8_t (*) [n])0)[1+n][0]) ) >> 1;
7 | }
8 |
9 | int main() {
10 | printf("%d\n", rich(10));
11 |
12 | return 0;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/053-正则表达式匹配/re.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 |
4 |
5 |
6 | import re
7 |
8 | class Solution:
9 | # @return a boolean
10 | def isMatch(self, s, p):
11 | return re.match('^' + p + '$', s) != None
12 |
13 | # debug
14 | s = Solution()
15 | print s.isMatch("aa", "a*")
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/README.md:
--------------------------------------------------------------------------------
1 | ChineseCodingInterviewAppendix
2 | ==============================
3 |
4 | [zhedahht/ChineseCodingInterviewAppendix](https://github.com/zhedahht/ChineseCodingInterviewAppendix)
5 | [微软、Google等面试题](http://zhedahht.blog.163.com/)
6 |
7 | The source code for the appendix part of the Chinese version of the book Coding Interviews
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Compiled Dynamic libraries
12 | *.so
13 | *.dylib
14 | *.dll
15 |
16 | # Fortran module files
17 | *.mod
18 |
19 | # Compiled Static libraries
20 | *.lai
21 | *.la
22 | *.a
23 | *.lib
24 |
25 | # Executables
26 | *.exe
27 | *.out
28 | *.app
29 |
--------------------------------------------------------------------------------
/template/template.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 |
21 |
22 | int __tmain( )
23 | {
24 | debug <<"test" <
2 | #include
3 |
4 |
5 |
6 | // 调试开关
7 | #define DEBUG
8 |
9 |
10 | #ifdef DEBUG
11 |
12 | #define debug cout
13 | #define dprintf printf
14 |
15 | #else
16 |
17 | #define debug 0 && cout
18 | #define dprintf 0 && printf
19 |
20 | #endif // DEBUG
21 |
22 |
23 |
24 |
25 | int main( )
26 | {
27 | freopen("in.txt", "r", stdin);
28 | //freopen("out.txt", "w", stdout);
29 |
30 | int a, b;
31 | while(scanf("%d%d", &a, &b) != EOF)
32 | {
33 | printf("%d\n", a + b);
34 | }
35 |
36 |
37 | return 0;
38 | }
39 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/Utilities/BinaryTree.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct BinaryTreeNode
4 | {
5 | int m_nValue;
6 | BinaryTreeNode* m_pLeft;
7 | BinaryTreeNode* m_pRight;
8 | };
9 |
10 | __declspec( dllexport ) BinaryTreeNode* CreateBinaryTreeNode(int value);
11 | __declspec( dllexport ) void ConnectTreeNodes(BinaryTreeNode* pParent, BinaryTreeNode* pLeft, BinaryTreeNode* pRight);
12 | __declspec( dllexport ) void PrintTreeNode(BinaryTreeNode* pNode);
13 | __declspec( dllexport ) void PrintTree(BinaryTreeNode* pRoot);
14 | __declspec( dllexport ) void DestroyTree(BinaryTreeNode* pRoot);
15 |
--------------------------------------------------------------------------------
/046-求1+2+3+...+n/functemplate.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | template < unsigned int n>
21 | struct Sum
22 | {
23 | enum Value
24 | {
25 | N = Sum< n - 1 >::N + n
26 | };
27 | };
28 |
29 | template <>
30 | struct Sum<1>
31 | {
32 | enum Value
33 | {
34 | N = 1
35 | };
36 | };
37 |
38 |
39 | int main( )
40 | {
41 |
42 | cout <::N <
2 | #include
3 |
4 | using namespace std;
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 |
21 | class Solutin
22 | {
23 | public :
24 | void Print(int n)
25 | {
26 | int max = pow(10, n);
27 | for(int i = 1; i < max; i++)
28 | {
29 | cout <> n)
42 | {
43 |
44 | solu.Print(n);
45 | }
46 | return 0;
47 | }
48 |
--------------------------------------------------------------------------------
/048-不能被继承的类/static_func.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class SealedClass
21 | {
22 | public :
23 | static SealedClass* GetInstance( )
24 | {
25 | return new SealedClass( );
26 | }
27 | private :
28 | SealedClass( ){ }
29 | ~SealedClass( ){ };
30 |
31 | };
32 |
33 | class Base : public SealedClass
34 | {
35 | };
36 |
37 | int __tmain( )
38 | {
39 | SealedClass *pb = Base::GetInstance( );
40 | Base base;
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/template/oj.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 |
7 | using namespace std;
8 |
9 |
10 |
11 | // 调试开关
12 | #define DEBUG
13 |
14 |
15 | #ifdef DEBUG
16 |
17 | #define debug cout
18 | #define dprintf printf
19 |
20 | #else
21 |
22 | #define debug 0 && cout
23 | #define dprintf 0 && printf
24 |
25 | #endif // DEBUG
26 |
27 |
28 |
29 |
30 | int main( )
31 | {
32 | freopen("in.txt", "r", stdin);
33 | //freopen("out.txt", "w", stdout);
34 |
35 | int a, b;
36 | while(scanf("%d%d", &a, &b) != EOF)
37 | {
38 | printf("%d\n", a + b);
39 | }
40 |
41 |
42 | return EXIT_SUCCESS;
43 | }
44 |
--------------------------------------------------------------------------------
/047-不用加减乘除做加法/inline_asm.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class Solution
21 | {
22 | public:
23 | int Add(int left, int right)
24 | {
25 | __asm__ __volatile__
26 | (
27 | //"lock;\n"
28 | "addl %1,%0;\n" /* 相当于 add b, a结果存储在a中*/
29 | : "=m"(left)
30 | : "r"(right), "m"(left)
31 | // :
32 | );
33 |
34 | return left;
35 | }
36 | };
37 |
38 | int __tmain( )
39 | {
40 | Solution solu;
41 |
42 |
43 | cout <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class SealedClass
21 | {
22 | private :
23 | SealedClass( ){ }
24 | ~SealedClass( ){ }
25 |
26 | public :
27 | friend SealedClass* GetInstance( );
28 |
29 | };
30 |
31 |
32 | SealedClass* GetInstance( )
33 | {
34 | return new SealedClass( );
35 | }
36 |
37 |
38 | class Base : public SealedClass
39 | {
40 | };
41 |
42 | int __tmain( )
43 | {
44 | SealedClass *p = GetInstance( );
45 |
46 | //Base base; // error
47 |
48 | return 0;
49 | }
50 |
--------------------------------------------------------------------------------
/046-求1+2+3+...+n/recursion.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 | class Solution
20 | {
21 | public:
22 | int Sum_Solution(int n)
23 | {
24 | return 0;
25 | }
26 |
27 | int SumRecursion(int n)
28 | {
29 | int ans = n;
30 | debug <
2 | #include
3 | #include
4 |
5 |
6 | using namespace std;
7 |
8 |
9 |
10 | #define __tmain main
11 |
12 | #ifdef __tmain
13 |
14 | #define debug cout
15 |
16 | #else
17 |
18 | #define debug 0 && cout
19 |
20 | #endif // __tmain
21 |
22 |
23 | class Solution
24 | {
25 | public:
26 | int GetNumberOfK(vector data ,int k)
27 | {
28 | int upper = upper_bound(data.begin(),data.end(),k);
29 | int low = lower_bound(data.begin(),data.end(),k);
30 | return upper - low;
31 | }
32 | };
33 |
34 | int __tmain( )
35 | {
36 | Solution solu;
37 |
38 | int arr[] = { 1, 2, 3, 3, 3, 3, 4, 5 };
39 | vector vec(arr, arr + 8);
40 | cout <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 |
21 | class CNoHeritance
22 | {
23 | friend class SealedClass;
24 | private:
25 | CNoHeritance(){ }
26 | ~CNoHeritance(){ }
27 | };
28 |
29 |
30 |
31 | class SealedClass : virtual public CNoHeritance
32 | {
33 | public:
34 | SealedClass( ){ }
35 |
36 | ~SealedClass( ){ }
37 | };
38 |
39 |
40 | /*
41 | class Base : public SealedClass
42 | {
43 | public:
44 | Base():SealedClass( ){ }
45 | ~Base(){ }
46 | };
47 | */
48 |
49 | int __tmain( )
50 | {
51 | SealedClass sc;
52 | //Base base;
53 |
54 | return 0;
55 | }
56 |
--------------------------------------------------------------------------------
/048-不能被继承的类/final.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 |
21 | template
22 | class CNoHeritance
23 | {
24 | friend T;
25 | private:
26 | CNoHeritance(){ }
27 | ~CNoHeritance(){ }
28 | };
29 |
30 |
31 |
32 | class SealedClass : virtual public CNoHeritance
33 | {
34 | public:
35 | SealedClass( ){ }
36 |
37 | ~SealedClass( ){ }
38 | };
39 |
40 | /*
41 | class Base : public SealedClass
42 | {
43 | public:
44 | Base():SealedClass( ){ }
45 | ~Base(){ }
46 | };
47 | */
48 |
49 | int __tmain( )
50 | {
51 | SealedClass sc;
52 | //Base base;
53 |
54 | return 0;
55 | }
56 |
--------------------------------------------------------------------------------
/038-数字在排序数组中出现的次数/04-multiset.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 |
6 | using namespace std;
7 |
8 |
9 |
10 | // 调试开关
11 | #define __tmain main
12 |
13 | #ifdef __tmain
14 |
15 | #define debug cout
16 |
17 | #else
18 |
19 | #define debug 0 && cout
20 |
21 | #endif // __tmain
22 |
23 |
24 | class Solution
25 | {
26 | public:
27 | int GetNumberOfK(vector data ,int k)
28 | {
29 | multiset mData;
30 | for(int i = 0; i < data.size( ); i++)
31 | {
32 | mData.insert(data[i]);
33 | }
34 |
35 | return mData.count(k);
36 | }
37 | };
38 |
39 | int __tmain( )
40 | {
41 | Solution solu;
42 |
43 | int arr[] = { 1, 2, 3, 3, 3, 3, 4, 5 };
44 | vector vec(arr, arr + 8);
45 | cout <
2 |
3 | using namespace std;
4 |
5 | // 调试开关
6 | #define __tmain main
7 |
8 | #ifdef __tmain
9 |
10 | #define debug cout
11 |
12 | #else
13 |
14 | #define debug 0 && cout
15 |
16 | #endif // __tmain
17 |
18 |
19 | class Solution
20 | {
21 | public:
22 | string LeftRotateString(string str, int n)
23 | {
24 | /// abcXYZdef
25 | /// abcXYZdefabcXYZdef
26 | /// 012345678
27 | /// 新的串是两倍串第len位起始长度为n字串
28 | int length = str.size( );
29 |
30 | if(length == 0)
31 | {
32 | return "";
33 | }
34 | n = n % len;
35 | str += str;
36 |
37 | return str.substr(n, len);
38 | }
39 | };
40 |
41 |
42 | int __tmain( )
43 | {
44 | Solution solu;
45 |
46 | cout <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class Solution
21 | {
22 | public:
23 | int Add(int left, int right)
24 | {
25 | int temp;
26 | while(right != 0)
27 | {
28 | temp = left ^ right; // 计算不带进位的情况
29 | right = (left & right) <<1; // 计算带进位的情况
30 | left = temp;
31 | // now left = 不带进位的情况, right = 带进位的情况
32 | }
33 |
34 | return left;
35 | }
36 |
37 |
38 | int AddRecursion(int left, int right)
39 | {
40 | return right == 0 ? left : AddRecursion(left ^ right, (left & right) << 1);
41 | }
42 | };
43 |
44 | int __tmain( )
45 | {
46 | Solution solu;
47 |
48 |
49 | cout <
2 | #include
3 |
4 | using namespace std;
5 |
6 |
7 | // 调试开关
8 | #define __tmain main
9 |
10 | #ifdef __tmain
11 |
12 | #define debug cout
13 |
14 | #else
15 |
16 | #define debug 0 && cout
17 |
18 | #endif // __tmain
19 |
20 |
21 | class Solution
22 | {
23 | public:
24 | vector multiply(const vector& A)
25 | {
26 | int n = A.size();
27 | vector res(n);
28 | // C[i] = A[0] * A[1] * ... *A[i - 1]
29 | for(int i = 0, temp = 1; i < n; i++)
30 | {
31 | res[i] = temp;
32 | temp *= A[i];
33 | }
34 |
35 | // D[i] = A[i + 1] * A[i + 2] * ... *A[n - 1]
36 | for(int i = n - 1, temp = 1; i >= 0; i--)
37 | {
38 | res[i] *= temp;
39 | temp *= A[i];
40 |
41 | }
42 | return res;
43 | }
44 | };
45 |
46 | int __tmain( )
47 | {
48 | debug <<"test" <
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/KthNodeInBST/KthNodeInBST.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/StreamMedian/StreamMedian.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/042-翻转单词顺序列/04-reverse_temp.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | // 调试开关
6 | #define __tmain main
7 |
8 | #ifdef __tmain
9 |
10 | #define debug cout
11 |
12 | #else
13 |
14 | #define debug 0 && cout
15 |
16 | #endif // __tmain
17 |
18 |
19 | class Solution
20 | {
21 | public:
22 | string ReverseSentence(string str)
23 | {
24 | string result;
25 | while (str.rfind(" ") != -1)
26 | {
27 | unsigned long position = str.rfind(" ");
28 | string temp = str.substr(position + 1);
29 | //debug <
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/StringPathInMatrix/StringPathInMatrix.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/ArrayConstruction/ArrayConstruction.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/DuplicationInArray/DuplicationInArray.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/NextNodeInBinaryTrees/NextNodeInBinaryTrees.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/PrintTreesInLines/PrintTreesInLines.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/EntryNodeInListLoop/EntryNodeInListLoop.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/MaxInSlidingWindow/MaxInSlidingWindow.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/PrintTreesInZigzag/PrintTreesInZigzag.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/SerializeBinaryTrees/SerializeBinaryTrees.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/DeleteDuplicatedListNode/DeleteDuplicatedListNode.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/FirstCharacterInStream/FirstCharacterInStream.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ChineseCodingInterviewAppendix-master/SymmetricalBinaryTree/SymmetricalBinaryTree.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/038-数字在排序数组中出现的次数/01-bruteforce.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 |
5 | using namespace std;
6 |
7 |
8 |
9 | // 调试开关
10 | #define __tmain main
11 |
12 | #ifdef __tmain
13 |
14 | #define debug cout
15 |
16 | #else
17 |
18 | #define debug 0 && cout
19 |
20 | #endif // __tmain
21 |
22 |
23 | class Solution
24 | {
25 |
26 | public:
27 |
28 | int GetNumberOfK(vector data,int k)
29 | {
30 | if(data.size( ) == 0)
31 | {
32 | return 0;
33 | }
34 |
35 | int count = 0;
36 | for(unsigned int i = 0;
37 | i < data.size( ) && data[i] <= k;
38 | i++)
39 | {
40 | if(data[i] == k)
41 | {
42 | count++;
43 | }
44 | }
45 |
46 | return count;
47 | }
48 | };
49 |
50 | int __tmain( )
51 | {
52 | Solution solu;
53 |
54 | int arr[] = { 1, 2, 3, 3, 3, 3, 5, 6 };
55 | vector vec(arr, arr + 8);
56 | cout <
2 |
3 | using namespace std;
4 |
5 | // 调试开关
6 | #define __tmain main
7 |
8 | #ifdef __tmain
9 |
10 | #define debug cout
11 |
12 | #else
13 |
14 | #define debug 0 && cout
15 |
16 | #endif // __tmain
17 |
18 | class Solution
19 | {
20 | public:
21 | string LeftRotateString(string str, int n)
22 | {
23 | if(str.size( ) == 0)
24 | {
25 | return "";
26 | }
27 | n %= str.size( );
28 |
29 | Reverse(str, 0, n - 1);
30 | Reverse(str, n, str.size( ) - 1);
31 | Reverse(str, 0, str.size( ) - 1);
32 |
33 | return str;
34 | }
35 |
36 | void Reverse(string &str, int left, int right)
37 | {
38 | while(left < right)
39 | {
40 | swap(str[left], str[right]);
41 |
42 | left++;
43 | right--;
44 | }
45 | }
46 | };
47 |
48 |
49 | int __tmain( )
50 | {
51 | Solution solu;
52 |
53 | cout <
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/036-数组中的逆序对/01-bruteforce.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | using namespace std;
5 |
6 | #define __tmain main
7 |
8 | #ifdef __tmain
9 |
10 | #define debug cout
11 |
12 | #else
13 |
14 | #define debug 0 && cout
15 |
16 | #endif // __tmain
17 |
18 |
19 | class Solution
20 | {
21 | public:
22 | int InversePairs(vector elem)
23 | {
24 | if(elem.size( ) == 0)
25 | {
26 | return 0;
27 | }
28 |
29 | int count = 0;
30 | for(unsigned int i = 0; i < elem.size( ); i++) /// 循环每一个位置的数据
31 | {
32 | for(unsigned int j = i + 1; j < elem.size( ); j++) /// 依次判断后面的数据与当前位置数据是否是逆序
33 | {
34 | if(elem[i] > elem[j])
35 | {
36 | count++;
37 | }
38 | }
39 | }
40 |
41 | return count;
42 | }
43 | };
44 |
45 | int __tmain( )
46 | {
47 | Solution solu;
48 |
49 | int arr[] = { 7, 5, 6, 4 };
50 | vector vec(arr, arr + 4);
51 |
52 | cout <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class SealedClass
21 | {
22 | public :
23 | static SealedClass* GetInstance( )
24 | {
25 | if(m_sc == NULL)
26 | {
27 | m_sc = new SealedClass( );
28 | }
29 |
30 | return m_sc;
31 | }
32 | static void Destroy( )
33 | {
34 | if(m_sc != NULL)
35 | {
36 | delete m_sc;
37 | }
38 | }
39 | private :
40 | SealedClass( ){ }
41 | ~SealedClass( ){ }
42 |
43 |
44 | static SealedClass *m_sc;
45 | };
46 |
47 |
48 | SealedClass* SealedClass::m_sc = NULL;
49 |
50 |
51 | class Base : public SealedClass
52 | {
53 | };
54 |
55 |
56 | int __tmain( )
57 | {
58 | SealedClass *pb = SealedClass::GetInstance( );
59 | SealedClass::Destroy( );
60 |
61 | pb = NULL;
62 |
63 | //Base b; // error
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/004-替换空格/replacespace2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | #define __tmain main
6 |
7 |
8 | class Solution
9 | {
10 | public:
11 | void replaceSpace(char *str,int length)
12 | {
13 | int i, j;
14 | int count = 0;
15 | int len = length;
16 | for(int i = 0; i < length; i++)
17 | {
18 | if(str[i] == ' ')
19 | {
20 | count++;
21 | }
22 | }
23 |
24 | len = length + count * 2;
25 | for(i = length - 1, j = len - 1;
26 | i >= 0 && j >= 0;)
27 | {
28 | if(str[i] == ' ')
29 | {
30 | str[j--] = '0';
31 | str[j--] = '2';
32 | str[j--] = '%';
33 | i--;
34 | }
35 | else
36 | {
37 | str[j--] = str[i--];
38 | }
39 | }
40 | str[len] = '0';
41 |
42 | }
43 | };
44 |
45 |
46 | int __tmain( )
47 | {
48 | char str[10 + 1] = "a b c d";
49 |
50 | Solution solu;
51 | solu.replaceSpace(str, 10);
52 |
53 | cout <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class base;
21 | base *parray[2];
22 |
23 | class base{
24 | public:
25 | virtual unsigned int sum(unsigned int n)
26 | {
27 | // 递归的终止
28 | return 0;
29 | }
30 | };
31 |
32 | class derive :public base{
33 | public:
34 | virtual unsigned int sum(unsigned int n)
35 | {
36 | // !!n两次非运算, 从而将n转换为bool类型, 来选择函数
37 | // sum(n) = sum(n - 1) + n 则是递归公式
38 | return parray[!!n]->sum(n - 1) + n;
39 | }
40 | };
41 |
42 |
43 | class Solution {
44 | public:
45 | int Sum_Solution(int n) {
46 |
47 | base a;
48 | derive b;
49 |
50 | parray[0] = &a;
51 | parray[1] = &b;
52 |
53 | return parray[1]->sum(n);
54 | }
55 | };
56 |
57 |
58 | int main(){
59 |
60 | Solution s;
61 |
62 | cout<
2 |
3 | using namespace std;
4 |
5 | // 调试开关
6 | #define __tmain main
7 |
8 | #ifdef __tmain
9 |
10 | #define debug cout
11 |
12 | #else
13 |
14 | #define debug 0 && cout
15 |
16 | #endif // __tmain
17 |
18 |
19 | class Solution
20 | {
21 | public:
22 | string ReverseSentence(string str)
23 | {
24 | if(str.size( ) == 0)
25 | {
26 | return str;
27 | }
28 | string res = "", tmp = "";
29 | for(unsigned int i = 0; i < str.size(); ++i)
30 | {
31 | if(str[i] == ' ') // 发现一个单词
32 | {
33 | debug <
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class base;
21 | base *parray[2];
22 |
23 | class base{
24 | public:
25 | virtual unsigned int sum(unsigned int n)
26 | {
27 | // 递归的终止
28 | return 0;
29 | }
30 | };
31 |
32 | class derive :public base{
33 | public:
34 | virtual unsigned int sum(unsigned int n)
35 | {
36 | // !!n两次非运算, 从而将n转换为bool类型, 来选择函数
37 | // sum(n) = sum(n - 1) + n 则是递归公式
38 | return parray[!!n]->sum(n - 1) + n;
39 | }
40 | };
41 |
42 |
43 | class Solution
44 | {
45 | public:
46 | int Sum_Solution(int n)
47 | {
48 |
49 | base a;
50 | derive b;
51 |
52 | parray[0] = &a;
53 | parray[1] = &b;
54 |
55 | return parray[1]->sum(n);
56 | }
57 | };
58 |
59 |
60 | int main(){
61 |
62 | Solution s;
63 |
64 | cout<
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 |
20 | class base;
21 | base *parray[2];
22 |
23 | class base{
24 | public:
25 | virtual unsigned int sum(unsigned int n)
26 | {
27 | // 递归的终止
28 | return 0;
29 | }
30 | };
31 |
32 | class derive :public base{
33 | public:
34 | virtual unsigned int sum(unsigned int n)
35 | {
36 | // !!n两次非运算, 从而将n转换为bool类型, 来选择函数
37 | // sum(n) = sum(n - 1) + n 则是递归公式
38 | return parray[!!n]->sum(n - 1) + n;
39 | }
40 | };
41 |
42 |
43 | class Solution
44 | {
45 | public:
46 | int Sum_Solution(int n)
47 | {
48 |
49 | base a;
50 | derive b;
51 |
52 | parray[0] = &a;
53 | parray[1] = &b;
54 |
55 | return parray[1]->sum(n);
56 | }
57 | };
58 |
59 |
60 | int main(){
61 |
62 | Solution s;
63 |
64 | cout<
2 |
3 |
4 | using namespace std;
5 |
6 |
7 | // 调试开关
8 | #define __tmain main
9 |
10 | #ifdef __tmain
11 |
12 | #define debug cout
13 |
14 | #else
15 |
16 | #define debug 0 && cout
17 |
18 | #endif // __tmain
19 |
20 |
21 |
22 | class Solution
23 | {
24 | public:
25 | string LeftRotateString(string str, int n)
26 | {
27 | if(str.size( ) == 0)
28 | {
29 | return "";
30 | }
31 | n %= str.size( );
32 | Reverse(str.begin( ), str.begin( ) + n - 1);
33 | Reverse(str.begin( ) + n, str.end( ) - 1);
34 | Reverse(str.begin( ), str.end( ) - 1);
35 |
36 | return str;
37 | }
38 |
39 | void Reverse(string::iterator left, string::iterator right)
40 | {
41 | while(left < right)
42 | {
43 | debug <<*left <<", " <<*right <
2 | #include
3 | using namespace std;
4 |
5 |
6 |
7 | ///if p[j+1] == '*' -> (i + 1, j + 1)
8 | ///else if p[i] == p[j] -> (i + 1, j + 2) or (i, j+2)
9 | ///else -> (i, j+2)
10 |
11 | class Solution
12 | {
13 | public:
14 | bool match(const char *s, const char *p)
15 | {
16 | if (*p == '\0') // 正则p到底末尾时
17 | {
18 | return !(*s); // 如果串s页到达末尾,则匹配成功
19 | }
20 |
21 | int slen = strlen(s), plen = strlen(p);
22 |
23 | if (plen == 1 // 如果正则串只有一个长度
24 | || *(p + 1) != '*') // 如果匹配*
25 | {
26 | //
27 | return slen && (p[0] == '.' || *s == *p)
28 | && match(s + 1, p + 1);
29 | }
30 | else
31 | {
32 | // 匹配一个字符
33 | while (*s != '\0' && (*p == '.' || *s == *p))
34 | {
35 | if (match(s++, p + 2))
36 | {
37 | return true;
38 | }
39 | }
40 | }
41 |
42 | // 匹配0个字符
43 | return match(s, p + 2);
44 | }
45 | };
46 |
47 |
48 |
49 | int main(void)
50 | {
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/046-求1+2+3+...+n/constructor.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | // 调试开关
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 | class Temp
20 | {
21 | public :
22 | Temp( )
23 | {
24 | ++N;
25 | Sum += N;
26 | }
27 |
28 | static void Reset( )
29 | {
30 | N = 0;
31 | Sum = 0;
32 | }
33 |
34 | static unsigned int GetSum( )
35 | {
36 | return Sum;
37 | }
38 |
39 | private :
40 | static unsigned int N;
41 | static unsigned int Sum;
42 | };
43 |
44 | unsigned int Temp::N = 0;
45 | unsigned int Temp::Sum = 0;
46 |
47 |
48 |
49 | class Solution
50 | {
51 | public:
52 | int res;
53 | int Sum_Solution(int n)
54 | {
55 | Temp::Reset( );
56 |
57 | Temp *a = new Temp[n];
58 | delete[] a;
59 | a = NULL;
60 |
61 | return Temp::GetSum( );
62 | }
63 | };
64 |
65 | // 5 4 3 2 1
66 | int __tmain(void)
67 | {
68 | Solution solu;
69 | cout <
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | // 调试开关
8 | #define __tmain main
9 |
10 | #ifdef __tmain
11 |
12 | #define debug cout
13 |
14 | #else
15 |
16 | #define debug 0 && cout
17 |
18 | #endif // __tmain
19 |
20 |
21 | class Solution
22 | {
23 | public:
24 | int LastRemaining_Solution(unsigned int n, unsigned int m)
25 | {
26 | if(n < 1 || m < 1)
27 | {
28 | return -1;
29 | }
30 | else if(n == 1)
31 | {
32 | return 0;
33 | }
34 | else
35 | {
36 | // F[n] = (F[n - 1] + m) % n
37 | return (LastRemaining_Solution(n - 1, m) + m) % n;
38 | }
39 | }
40 | };
41 |
42 | int __tmain( )
43 | {
44 | Solution solu;
45 | /*
46 | 0 1 2 3 4 -=> 1 leave, last = 0, m = 2, step = 2,
47 | 0 2 3 4 -=> 3 leave, last = 0, m = 2, step = 3,
48 | 0 2 4 -=> 0 leave, last = 2, m = 2, step = 4,
49 | 2 4 -=> 4 leave
50 | 2 -=> 2 win
51 | */
52 | cout <
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | // µ÷ÊÔ¿ª¹Ø
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 | class Solution
20 | {
21 | public:
22 | //下面这种迭代的方法时间复杂度为O(n^2)
23 | bool VerifySquenceOfBST_Iteratively(const vector& sequence) {
24 | int left = 0, right = sequence.size() - 1;
25 | while (left < right && right != 0) {
26 | //循环结束时,left是第一个大于根的元素的位置,即右子树首元素下标
27 | while (sequence[left] < sequence[right])
28 | left++;
29 | //循环结束时,left越过右子树末节点,到达根节点
30 | while (sequence[left] > sequence[right])
31 | left++;
32 |
33 | //如果没有到达根节点,说明不满足左子树所有节点小于根节点,右子树所有节点大于根节点的条件
34 | if (left < right)
35 | return false;
36 | left = 0;
37 |
38 | right--;
39 | }
40 |
41 | //如果循环一直到right == 0才终止, 说明以所有节点为根节点,左侧序列均满足后序遍历序列的条件
42 | return (right == 0) ? true : false;
43 | }
44 | };
45 |
46 |
47 | int __tmain( )
48 | {
49 | // 10
50 | // 6 14
51 | // 8 12 16
52 | //4
53 |
54 |
55 |
56 |
57 | int a[] = { 1, 2, 3 };
58 |
59 | vector vec(a, a + 3);
60 |
61 | Solution solu;
62 | cout <
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/041-和为S的两个数字/find.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 |
5 | using namespace std;
6 |
7 |
8 | // 调试开关
9 | #define __tmain main
10 |
11 | #ifdef __tmain
12 |
13 | #define debug cout
14 |
15 | #else
16 |
17 | #define debug 0 && cout
18 |
19 | #endif // __tmain
20 |
21 |
22 | class Solution
23 | {
24 |
25 | public :
26 |
27 | vector FindNumbersWithSum(vector array,int sum)
28 | {
29 | vector res;
30 |
31 | if (array.size( ) < 2)
32 | {
33 | return res;
34 | }
35 |
36 | int start = 0, end = array.size( ) - 1;
37 | long curSum;
38 |
39 | while (start < end)
40 | {
41 | curSum = array[start] + array[end];
42 |
43 | if (curSum == sum)
44 | {
45 | /// 左右夹逼
46 | /// 同时能保证乘积最小的
47 | /// 和为sum的最大的两个数最接近sqrt(sum)
48 | res.push_back(array[start]);
49 | res.push_back(array[end]);
50 |
51 | break;
52 | }
53 | else if (curSum < sum)
54 | {
55 | start++;
56 | }
57 | else
58 | {
59 | end--;
60 | }
61 | }
62 |
63 | return res;
64 | }
65 | };
66 |
67 | int __tmain( )
68 | {
69 | debug <<"test" <
2 | #include
3 | #include
4 |
5 |
6 | using namespace std;
7 |
8 |
9 |
10 | #define __tmain main
11 |
12 | #ifdef __tmain
13 |
14 | #define debug cout
15 |
16 | #else
17 |
18 | #define debug 0 && cout
19 |
20 | #endif // __tmain
21 |
22 | ///////////////////////////////////
23 | // error
24 | ///////////////////////////////////
25 | class Solution
26 | {
27 | public:
28 | //从data末端开始,对每个数进行插入排序 其插入入的位置与其当前位置之差 即为当前数字的逆序个数
29 | int InversePairs(vector elem)
30 | {
31 | // 排序部分
32 | int i, j, temp;
33 | int count = 0, length = elem.size( );
34 |
35 | for(i = 1; i < length; i++) // 循环第1个数据以后的每个数据
36 | {
37 | temp = elem[i]; // 保存第i个数据,
38 | for(j = i - 1; j >= 0 && temp < elem[j]; j--) // 将比保存的数据都往后移
39 | {
40 | elem[j + 1] = elem[j];
41 | count++;
42 | }
43 | // 循环结束后就在有序的0-i的位置中找到了temp应该插入的位置(j + 1)
44 | elem[j + 1] = temp; // 将保存的数据插进来
45 | }
46 |
47 | copy(elem.begin(), elem.end(), ostream_iterator(cout," "));
48 | return count;
49 | }
50 | };
51 |
52 | int __tmain( )
53 | {
54 | Solution solu;
55 |
56 | int arr[] = { 7, 6, 5, 4};
57 | vector vec(arr, arr + 4);
58 |
59 | cout <
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | #define __tmain main
8 |
9 | #ifdef __tmain
10 |
11 | #define debug cout
12 |
13 | #else
14 |
15 | #define debug 0 && cout
16 |
17 | #endif // __tmain
18 |
19 | class Solution
20 | {
21 | public:
22 | int MoreThanHalfNum_Solution(vector numbers)
23 | {
24 | // return numbers.empty( ) ? 0 : *find_if(numbers.begin( ), numbers.end( ),[numbers](int x)
25 | // {
26 | // return (count(numbers.begin( ),numbers.end( ), x) * 2) > numbers.size();
27 | // });
28 |
29 | if(numbers.size( ) == 0)
30 | {
31 | return 0;
32 | }
33 | for(int i = 0 ; i < numbers.size( ); i++)
34 | {
35 | debug <<"num = " <
2 | #include
3 | #include
4 | #include
5 |
6 |
7 | using namespace std;
8 |
9 |
10 | // 调试开关
11 | #define __tmain main
12 |
13 | #ifdef __tmain
14 |
15 | #define debug cout
16 |
17 | #else
18 |
19 | #define debug 0 && cout
20 |
21 | #endif // __tmain
22 |
23 | class Solution
24 | {
25 | typedef pair Pair;
26 | public :
27 | vector maxInWindows(const vector &num, unsigned int size)
28 | {
29 | vector result;
30 | priority_queue Q;
31 | if (num.size() < size || size < 1)
32 | {
33 | return result;
34 | }
35 |
36 | for (int i = 0; i < size-1; i++)
37 | {
38 | Q.push(Pair(num[i],i));
39 | }
40 |
41 | for (int i = size-1; i < num.size(); i++)
42 | {
43 | Q.push(Pair(num[i],i));
44 | Pair p = Q.top();
45 | while(p.second < i-(size-1)) {
46 | Q.pop();
47 | p = Q.top();
48 | }
49 | result.push_back(p.first);
50 | }
51 | // result.push_back(Q.top().first);
52 | return result;
53 | }
54 | };
55 | int __tmain( )
56 | {
57 | Solution solu;
58 |
59 | int array[] = { 2, 3, 4, 2, 6, 2, 5, 1 };
60 | vector vec(array, array + 8);
61 |
62 | vector res = solu.maxInWindows(vec, 3);
63 | copy(res.begin( ), res.end( ), ostream_iterator(cout," "));
64 |
65 | return 0;
66 | }
67 |
--------------------------------------------------------------------------------
/029-数组中出现次数超过一半的数字/05-map.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include