[数据结构]
fxf1012
这个作者很懒,什么都没留下…
展开
-
《剑指Offer》 面试题27:二叉搜索树与双向链表
《剑指Offer》 P151面试题27:二叉搜索树与双向链表题目输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。原创 2015-05-07 14:38:58 · 437 阅读 · 0 评论 -
《CTCI》3.5 用两个栈实现队列
《CTCI》 P1423 栈与队列题目3.5 实现一个MyQueue类,该类用两个栈来实现一个队列。解答#include <stack>template <typename T> class queue{public: void push(const T& val); void pop(); const T& front(); const T& back();原创 2015-05-08 21:52:44 · 359 阅读 · 0 评论 -
《剑指Offer》面试题28:字符串的排列
《剑指Offer》 P154面试题28:字符串的排列题目解答//面试题28:字符串的全排列#include <string>#include <iostream>#include <Windows.h>using namespace std;void permutation(string s,int start,int &num){ if (start == s.size() - 1)原创 2015-05-08 16:19:51 · 1506 阅读 · 0 评论 -
《CTCI》2.7 检查链表是否为回文
《CITI》P12 链表题目:2.7 Implement a function to check if a linked list is a palindrome原创 2015-04-25 11:17:45 · 312 阅读 · 0 评论 -
《CTCI》2.2 单项链表中倒数第k个结点
《CITI》P1182 链表题目:2.2 Implement an algorithm to find the kth to last element of a singly linked list.原创 2015-04-25 11:04:39 · 337 阅读 · 0 评论 -
《CTCI》2.5 链表表示的整数求和
《CITI》P1232 链表题目:2.5 You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1 ‘s digit is at the head of the l原创 2015-04-25 11:09:56 · 392 阅读 · 0 评论 -
《CTCI》2.6 寻找有环链表的开头结点
《CITI》P1262 链表题目:2.6 Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.原创 2015-04-25 11:17:05 · 312 阅读 · 0 评论 -
《CTCI》2.3 删除链表某结点
《CITI》P12 链表题目:2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.原创 2015-04-25 11:06:21 · 283 阅读 · 0 评论 -
《CTCI》2.4 划分链表
《CITI》P1212 链表题目:2.4 Write code to partition a linked list around a value x, such that all nodes less than x come before alt nodes greater than or equal to x.原创 2015-04-25 11:07:58 · 324 阅读 · 0 评论 -
《CTCI》2.1 移除未排序链表中的重复结点
《CITI》P1172 链表题目:2.1 Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve this problem if a temporary buffer is not allowed?原创 2015-04-25 11:01:34 · 492 阅读 · 0 评论 -
《CTCI》1.8 调用一次isSubstring判断旋转字符串
《CITI》P1161 数组与字符串题目:1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, si and s2, write code to check Ifs2 is a rotation of si using only o原创 2015-04-24 22:23:49 · 566 阅读 · 0 评论 -
《CTCI》1.7 二维数组的含0元素所在行列清零
《CITI》P1151 数组与字符串题目:1.7 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.原创 2015-04-24 22:20:20 · 870 阅读 · 0 评论 -
LeetCode 26 Remove Duplicates from Sorted Array
LeetCode26 Remove Duplicates from Sorted Array题目Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for an原创 2015-05-07 21:19:12 · 293 阅读 · 0 评论 -
LeetCode 80 Remove Duplicates from Sorted Array II
LeetCode80 Remove Duplicates from Sorted Array II题目Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function s原创 2015-05-08 16:15:15 · 328 阅读 · 0 评论 -
LeetCode 1 TwoSum
LeetCode1.TwoSumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the原创 2015-04-30 15:18:15 · 274 阅读 · 0 评论 -
《CTCI》3.3 栈之栈
《CITI》P1373 栈与队列题目:3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some原创 2015-04-28 11:14:19 · 462 阅读 · 0 评论 -
《CTCI》3.4 汉诺塔游戏
《CTCI》 P1403 栈与队列题目3.4 In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending o原创 2015-05-07 17:05:18 · 464 阅读 · 0 评论 -
《剑指Offer》面试题26:复杂链表的复制
《剑指Offer》 P147面试题26:复杂链表的复制题目请实现函数ComplexListNode* Clone(ComplexListNode* pHead),复制一个复杂链表。在复杂链表中,每个结点除了有一个m_pNext指针指向下一个结点外,还有一个m_pSibling指向链表中的任意结点或者NULL。结点的C++定义如下:struct ComplexListNode{ int m_原创 2015-05-07 12:42:35 · 942 阅读 · 0 评论 -
《剑指Offer》面试题33:把数组排成最小的数
//面试题33:把数组排成最小的数#include <iostream>#include <vector>#include <string>#include <sstream>#include <Windows.h>using namespace std;const int prec = numeric_limits<long double>::digits10;//模板函数:类型转换原创 2015-05-15 15:39:56 · 1023 阅读 · 0 评论 -
LeetCode 36 Valid Sudoku
LeetCode36 Valid Sudoku题目Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A parti原创 2015-05-04 15:53:17 · 343 阅读 · 0 评论 -
《CTCI》3.7 “猫狗”队列
《CITI》P1453 栈与队列题目:3.7 An animal shelter holds only dogs and cats, and operates on a strictly “first in, first out” basis. People must adopt either the “oldest” (based on arrival time) of all animals a原创 2015-04-28 11:22:22 · 384 阅读 · 0 评论 -
《CTCI》3.6 用两个栈实现排序栈
《CITI》P1433 栈与队列题目:3.6 Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you may not copy the elements into any原创 2015-04-28 11:21:26 · 424 阅读 · 0 评论 -
LeetCode 2 Add Two Numbers
LeetCode2 Add Two Numbers题目You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbe原创 2015-04-30 22:37:30 · 333 阅读 · 0 评论 -
LeetCode 3 Longest Substring Without Repeating Characters
LeetCode3 Longest Substring Without Repeating Characters题目Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating let原创 2015-04-30 22:42:28 · 469 阅读 · 0 评论 -
《CTCI》1.6 旋转二维数组
《CITI》P1141 数组与字符串题目:1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?原创 2015-04-24 22:18:42 · 242 阅读 · 0 评论 -
《CTCI》1.5 字符串“压缩”
《CITI》P1121 数组与字符串题目:1.5 Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the “compressed” s原创 2015-04-24 22:16:39 · 458 阅读 · 0 评论 -
《剑指Offer》面试题21:包含min函数的栈
《剑指Offer》 P132面试题21:包含min函数的栈题目:原创 2015-04-24 10:16:43 · 652 阅读 · 0 评论 -
《剑指Offer》面试题18:树的子结构
《剑指Offer》 P117面试题18:树的子结构题目:原创 2015-04-24 10:03:13 · 293 阅读 · 0 评论 -
《剑指Offer》面试题17:合并两个排序的链表
《剑指Offer》 P114面试题17:合并两个排序的链表题目:原创 2015-04-24 10:03:16 · 354 阅读 · 0 评论 -
《剑指Offer》面试题16:反转链表
《剑指Offer》 P112面试题16:反转链表题目:原创 2015-04-24 09:57:09 · 439 阅读 · 0 评论 -
《剑指Offer》面试题14:调整数组顺序使奇数位于偶数前面
《剑指Offer》 P102面试题14:调整数组顺序使奇数位于偶数前面题目:原创 2015-04-24 09:51:39 · 399 阅读 · 0 评论 -
《剑指Offer》面试题12:打印1到最大的n位数
《剑指Offer》 P94面试题12:打印1到最大的n位数题目:原创 2015-04-24 09:44:51 · 880 阅读 · 0 评论 -
《剑指Offer》面试题5:从尾到头打印链表
《剑指Offer》 P51面试题5:从尾到头打印链表题目:原创 2015-04-23 21:51:36 · 513 阅读 · 0 评论 -
《剑指Offer》面试题8:旋转数组的最小数字
《剑指Offer》 P66面试题8:旋转数组的最小数字题目:原创 2015-04-23 22:02:15 · 616 阅读 · 0 评论 -
《剑指Offer》面试题4:替换空格
《剑指Offer》 P44面试题4:替换空格题目:原创 2015-04-23 21:49:42 · 421 阅读 · 0 评论 -
《剑指Offer》面试题6:重建二叉树
《剑指Offer》 P55面试题6:重建二叉树题目:原创 2015-04-23 21:56:05 · 355 阅读 · 0 评论 -
《剑指Offer》面试题7:用两个栈实现队列
《剑指Offer》 P59面试题7:用两个栈实现队列题目:原创 2015-04-23 21:59:33 · 440 阅读 · 0 评论 -
《剑指Offer》面试题24:二叉搜索树的后序遍历序列
《剑指Offer》 P140面试题24:二叉搜索树的后序遍历序列题目:原创 2015-04-24 10:24:19 · 398 阅读 · 0 评论 -
《剑指Offer》面试题22:栈的压入,弹出序列
《剑指Offer》 P134面试题22:栈的压入,弹出序列题目:原创 2015-04-24 10:19:10 · 547 阅读 · 0 评论 -
《剑指Offer》面试题23:从上到下打印二叉树
《剑指Offer》 P137面试题23:从上到下打印二叉树题目:原创 2015-04-24 10:22:32 · 321 阅读 · 0 评论