文章分类 - 算法
java实现
摘要:/* 如果将链表的尾部作为栈顶,那么每次进行入栈和出栈操作都需要遍历链表找到尾部,这样的时间复杂度是 O(n),其中 n 是链表的长度。 而将链表的头部作为栈顶,则可以在常量时间内完成插入和删除操作,因为只需调整链表头的指针即可,时间复杂度为 O(1)。 */ //与顺序表的链式存储不同,其头结点表
阅读全文
摘要:#include<iostream> using namespace std; const int MAX=100; template <typename T> class SeqList { private: T data[MAX]; int list;//指向最后一个元素的位置 public:
阅读全文
摘要://滑动窗口 int lengthOfLongestSubstring(char * s) { int len ,i,r,l,max; r = l =max = 0; //r-->右 l-->左; while(s[r]) {//当右指针指向的字符存在时,即没有结束滑动 for(i = l; i< r
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ //进位 //改善-->直接在原链表上加:将短链表的值加到新链表上 struct List
阅读全文
摘要://哈希表 typedef struct//自定义哈希表的结构 { int key; int val; UT_hash_handle hh;//初始化为NULL } hashTable; int* twoSum(int* nums, int numsSize, int target, int* re
阅读全文