
剑指offer(第2版)
文章平均质量分 59
IT求职者热门书籍,剑指offer的源码实现,可直接运行。
大团子
爱好计算机
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
剑指offer--面试题6:从头到尾打印链表
#include #include #include using namespace std; typedef struct node { int data; struct node *next; }Node,*LinkList; LinkList Create_List_Tail(int length) {//建立链表 Node *L,*s,*r; //L指向头结点,r原创 2017-06-27 21:26:24 · 305 阅读 · 0 评论 -
剑指offer--面试题4:二维数组中的查找
#include bool Find(int *matrix, int rows, int columns, int number) { bool found = false; if(matrix != NULL && rows >原创 2017-04-20 14:21:29 · 708 阅读 · 0 评论 -
剑指offer--面试题5:替换空格
#include "stdio.h" /*length 为字符数组string的总容量*/ void ReplaceBlank(char string[], int length) { if(string == NULL && length <= 0) return; int original_Length = 0; //字符串string的实际长度原创 2017-04-20 15:10:18 · 342 阅读 · 0 评论 -
剑指offer--面试题20:表示数值的字符串
#include #include bool scanUnsignedInteger(const char** str) //判断是否是0-9之间的数字; { const char* before = *str; while(**str != '\0' && **str >= '0' && **str <= '9') ++(*str); // 当str原创 2017-07-15 14:40:40 · 464 阅读 · 0 评论 -
剑指offer--面试题10:斐波那契数列
#include long long Fibonacci(unsigned n) {//简单的迭代方法,从下往上计算,首先根据f(0)和f(1)计算出f(2),再根据f(1)和f(2)计算出f(3)……以此类推。很容易理解,时间复杂度是O(n) int result[2]={0,1}; if(n<2) return result[n]; long long fx=0,fy=1,fn=原创 2017-07-07 15:34:50 · 254 阅读 · 0 评论 -
剑指offer--面试题15:二进制中1的个数
#include int NumberOf1_Solution1(int n) { int count = 0; unsigned int flag = 1; while (flag) { if (n & flag) count++; flag = flag << 1; } return原创 2017-07-12 11:23:11 · 273 阅读 · 0 评论 -
剑指offer--面试题16:数值的整数次方
#include #include double PowerWithUnsignedExponent(double base, unsigned int exponent) { if (exponent == 0) return 1; if (exponent == 1) return base; double result = P原创 2017-07-12 21:54:56 · 316 阅读 · 2 评论 -
剑指offer--面试题17:打印从1到最大的n位数
#include #include void PrintNumber(char* number); bool Increment(char* number); // ====================方法一==================== void Print1ToMaxN_1(int n) { if (n<= 0) return;原创 2017-07-14 15:45:09 · 279 阅读 · 0 评论 -
剑指offer--面试题19:正则表达式匹配
#include /* 在每轮匹配中,Patttern第二个字符是'*'时: 1、第一个字符不匹配('.'与任意字符视作匹配),那么'*'只能代表匹配0次,比如'ba'与'a*ba',字符串不变,模式向后移动两个字符,然后匹配剩余字符串和模式 2、第一个字符匹配,那么'*'可能代表匹配0次,1次,多次,比如'aaa'与'a*aaa'、'aba'与'a*ba'、'aaaba'与'a*ba'。匹配原创 2017-07-14 20:50:21 · 333 阅读 · 0 评论 -
剑指offer--面试题9:用两个栈实现队列
#include #include using namespace std; //***************数据结构******************* template class CQueue{ public: CQueue(void); ~CQueue(void); void appendTail(const T& node); T deleteHead(); priv原创 2017-07-05 21:22:11 · 279 阅读 · 2 评论 -
剑指offer--面试题3:数组中重复的数字
#include bool duplicate_1(int numbers[],int length,int *duplication) {//思想:遍历数组,假设遇到数字j,则将j换到下标为j的位置上,若再遇到相同数字j,对应位置上的数字已经==j。返回。 if(numbers==NULL||length<=0) return false; for(int i=0;i<length;++原创 2017-06-26 15:19:16 · 549 阅读 · 0 评论 -
剑指offer--面试题7:重建二叉树
#include #include using namespace std; typedef struct Node { struct Node* left; struct Node* right; char data; }*BTree; BTree Construct_Tree(char* pre, char* in, int lengt原创 2017-06-28 10:21:53 · 446 阅读 · 1 评论 -
剑指offer--面试题8:二叉树的下一个结点
#include struct BinaryTreeNode {//数据结构 int m_nValue; //数值域 BinaryTreeNode* m_pLeft; //左孩子指针 BinaryTreeNode* m_pRight; //右孩子指针 BinaryTreeNode*原创 2017-06-30 10:45:34 · 213 阅读 · 0 评论 -
剑指offer--面试题26:树的子结构
#include #define nullptr NULL struct BinaryTreeNode { double m_dbValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight; }; bool DoesTree1HaveTree2(Binary原创 2017-07-22 16:30:56 · 227 阅读 · 0 评论 -
剑指offer--面试题27:二叉树的镜像
#include #include #include #include using namespace std; typedef struct BTNode { char data; struct BTNode *lchild; struct BTNode *rchild; }BTNode,*BTree; void C原创 2017-07-22 19:51:52 · 285 阅读 · 0 评论 -
剑指offer--面试题28:对称的二叉树
#include #define nullptr NULL struct BinaryTreeNode { int m_nValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight; }; BinaryTreeNode* CreateBinar原创 2017-07-22 21:01:56 · 248 阅读 · 0 评论 -
剑指offer--面试题13:在O(1)时间删除链表结点
#include #include typedef struct node { int data; struct node *next; }Node,*LinkList; LinkList Create_Tail_LinkList(LinkList &L,int length) //尾插法建单链表 { Node * s,*r; L=(LinkList)malloc(sizeof(N原创 2017-04-22 21:09:34 · 650 阅读 · 0 评论 -
剑指offer--面试题18:删除链表的结点
#include #include struct ListNode { int m_nValue; ListNode* m_pNext; }; ListNode* CreateListNode(int value) { ListNode* pNode = new ListNode(); pNode->m_nValue = value; pN原创 2017-07-14 20:33:52 · 258 阅读 · 0 评论 -
剑指offer--面试题22:链表中倒数第k个节点
#include #include typedef struct node { int data; struct node *next; }Node,*LinkList; Node *FindKthToTail(LinkList L, unsigned int k) { if (L->next == NULL || k == 0原创 2017-07-15 16:07:44 · 279 阅读 · 0 评论 -
剑指offer--面试题23:链表中环的入口节点
#include #include #define nullptr NULL struct ListNode { int m_nValue; ListNode* m_pNext; }; ListNode* CreateListNode(int value) { ListNode* pNode = new ListNode();原创 2017-07-15 20:19:39 · 304 阅读 · 0 评论 -
剑指offer--面试题24:反转链表
#include #include //****************************************宏定义****************************************************** typedef int ElemType; typedef struct node { ElemType data; struct node *next; }N原创 2017-07-15 20:42:11 · 341 阅读 · 0 评论 -
剑指offer--面试题25:合并两个排序的链表
#include #include typedef struct Node { int data; struct Node *next; }LNode,*LinkList; LinkList Create_List() { int num; LNode *r,*s; LinkList L=(LinkList)malloc(sizeof(LNode)); L->next=NULL;原创 2017-07-22 14:46:00 · 270 阅读 · 0 评论 -
剑指offer--面试题13:机器人的运动范围
#include int movingCountCore(int threshold, int rows, int cols, int row, int col, bool* visited); bool check(int threshold, int rows, int cols, int row, int col, bool* visited); int getDigitSum(int原创 2017-07-11 16:20:42 · 368 阅读 · 0 评论 -
剑指offer--面试题14:剪绳子
#include #include // ====================动态规划==================== int maxProductAfterCutting_solution1(int length) { if(length < 2) return 0; if(length == 2) return 1; if原创 2017-07-12 10:32:50 · 1935 阅读 · 0 评论 -
剑指offer--面试题21:调整数组顺序使奇数位于偶数前面
#include void Reorder(int *pData, unsigned int length, bool (*func)(int)); bool isEven(int n); void ReorderOddEven(int *pData, unsigned int length) { Reorder(pData, length, isEven); } void Reo原创 2017-07-15 15:51:47 · 193 阅读 · 0 评论 -
剑指offer--面试题29:顺时针打印矩阵
#include void Print_Circle(int (*A)[3],int rows,int cols,int start) { int endX=cols-1-start; int endY=rows-1-start; //从左到右打印一行 for(int i=start;i<=endX;++i) printf("%d ",A[start][i]); //从上到下打印一列原创 2017-07-25 10:05:13 · 306 阅读 · 0 评论