06 2015 档案
摘要:思路: 通过增加一个辅助栈保存每个状态对应的最小值。栈实现的不完整,应该还包含empty()等常规函数。 1 #include 2 #include 3 using namespace std; 4 5 template class StackWithMin 6 { 7 public: 8...
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr...
阅读全文
摘要:思路: 比较两个链表端点值的大小,通过递归的方式排列。 1 #include 2 using namespace std; 3 4 struct ListNode 5 { 6 int val; 7 ListNode *next; 8 ListNode(int v = 0...
阅读全文
摘要:思路: 用三个指针preNode、curNode、nextNode完成。 1 #include 2 using namespace std; 3 4 struct ListNode 5 { 6 int val; 7 ListNode *next; 8 ListNode(...
阅读全文
摘要:思路: 定义两个指针同时指向head,第一个指针先走K-1步,随后二个指针同时移动,当第一个指针到末尾处时,第二个指针所指向的即为倒数第K个结点。 1 #include 2 using namespace std; 3 4 struct ListNode 5 { 6 int val; ...
阅读全文
摘要:思路: 头尾指针,向中间遍历,依据条件交换元素。 1 #include 2 using namespace std; 3 4 void reOrder(int *pData, unsigned int len, bool (*func)(int)) 5 { 6 if(pData == ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //构造链表结点 5 struct ListNode 6 { 7 int val; 8 ListNode *next; 9 10 ListNode(int v = 0):va...
阅读全文
摘要:思路: 用n位字符数组表示n位数,通过递归的方式逐层(位)遍历,递归终止时打印。 1 #include "stdio.h" 2 #include "string.h" 3 4 //打印“数字” 5 void printNum(char* number) 6 { 7 //设置前导零状态为开...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 template class SQueue 6 { 7 public: 8 SQueue():cnt(0){}; 9 10 void push(const T& node);1...
阅读全文
摘要:Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i...
阅读全文
摘要:Implement a trie withinsert,search, andstartsWithmethods.Note:You may assume that all inputs are consist of lowercase lettersa-z.思路: 构建一个简单的字典树,要求实现...
阅读全文
摘要:This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he wil...
阅读全文
摘要:There are a total ofncourses you have to take, labeled from0ton - 1.Some courses may have prerequisites, for example to take course 0 you have to firs...
阅读全文
摘要:Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For exampl...
阅读全文

浙公网安备 33010602011771号