
数据结构
M阳光
java
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
NYOJ 2 括号配对问题
链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=2 经典的问题,用栈解决。 发现如果原创 2014-04-19 16:22:09 · 700 阅读 · 0 评论 -
LeetCode 5 最长回文子串 Manacher线性算法
题目链接:https://oj.leetcode.com/problems/longest-palindromic-substring/回文串即正向反向序列都一样的连续序列 如abba,abcba...为了统一回文串的偶数情况和奇数情况,可以向串中插入不相关的字符,例如abba->#a#b#b#a#, abcba->#a#b#c#b#a#建立数组arr[]记录主串中以第原创 2015-01-26 12:19:47 · 717 阅读 · 0 评论 -
LeetCode Reorder List
链接: https://oj.leetcode.com/problems/reorder-list/空间复杂度为O(n),时间复杂度为 O(n)的代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * Lis原创 2014-12-04 13:55:13 · 395 阅读 · 0 评论 -
LeetCode Rotate List
链接: https://oj.leetcode.com/problems/rotate-list//** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * va原创 2014-12-05 21:39:24 · 447 阅读 · 0 评论 -
LeetCode Merge Two Sorted Lists
链接: https://oj.leetcode.com/problems/merge-two-sorted-lists/题目要去把两个有序的链表合并,并且合并后的链表依然有序./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *原创 2014-12-24 22:31:29 · 456 阅读 · 0 评论 -
LeetCode Majority Element
链接: https://oj.leetcode.com/problems/majority-element/LeetCode给的这道题的解答真的不错:Runtime: O(n2) — Brute force solution: Check each element if it is the majority element.Runtime: O(n), Space: O(n) —原创 2015-01-16 20:02:16 · 504 阅读 · 0 评论 -
LeetCode Swap Nodes in Pairs
链接:https://oj.leetcode.com/problems/swap-nodes-in-pairs/交换链表相邻的节点的位置/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int原创 2015-01-18 14:24:10 · 438 阅读 · 0 评论 -
Add Two Numbers
链接:https://oj.leetcode.com/problems/add-two-numbers/链表的大数加法/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) :原创 2015-01-20 20:08:30 · 492 阅读 · 0 评论 -
LeetCode Evaluate Reverse Polish Notation
链接: https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/后缀表达式求值class Solution{ public: int evalRPN(vector &tokens) { stack stk; int ans=0; for(int i=0;i<tokens.siz原创 2015-01-01 10:47:33 · 464 阅读 · 0 评论 -
LeetCode Longest Substring Without Repeating Characters
链接: https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/字符串中最长连续不重复子序列,用JAVA中的哈希表比较方便public class Solution { public int lengthOfLongestSubstring(String s) {原创 2015-01-22 23:50:34 · 530 阅读 · 0 评论 -
LeetCode Remove Nth Node From End of List
链接: https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/给链表添加哨兵,使用差速指针找到待删除节点的上一个节点,删除即可 。只需遍历一次链表/** * Definition for singly-linked list. * struct ListNode { * int va原创 2015-02-12 00:58:46 · 591 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted Array
链接:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/把有序数组中重复的元素删除,并返回删除后的数组长度。考虑直接插入排序的过程,如果遇见重复的元素,直接抛弃,判断下一个元素。由于数组本身有序,所以,时间复杂的为O(n).class Solution{ public:原创 2015-02-23 23:42:37 · 538 阅读 · 0 评论 -
LeetCode Partition List
链接: https://oj.leetcode.com/problems/partition-list/双重指针....../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : v原创 2014-11-27 17:26:53 · 421 阅读 · 0 评论 -
LeetCode Convert Sorted Array to Binary Search Tree
链接: https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/原创 2014-11-04 21:35:22 · 605 阅读 · 0 评论 -
HDU 1232 畅通工程(并查集分析)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232原创 2014-04-19 21:13:10 · 620 阅读 · 0 评论 -
priority_queue的用法
priority_queue调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式。先写一个用 STL 里面堆算法实现的与真正的STL里面的 priority_queue用法相似的priority_queue, 以加深对 priority_queue 的理解转载 2014-05-10 17:35:01 · 504 阅读 · 0 评论 -
HDU 1896 Stones
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896学了原创 2014-05-10 17:50:34 · 552 阅读 · 0 评论 -
HDU 1879 继续畅通工程
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1879原创 2014-07-16 16:45:35 · 543 阅读 · 0 评论 -
KMP算法的前缀next数组最通俗的解释
我们在一个母字符串中查找一个子字符串有很多方法。KMP是一种最常见的改进算法,它可以在匹配过程中失配的情况下,有效地多往后面跳几个字符,加快匹配速度。当然我们可以看到这个算法针对的是子串有对称属性,如果有对称属性,那么就需要向前查找是否有可以再次匹配的内容。 在KMP算法中有个数组,叫做前缀数组,也有的叫next数组,每一个子串有一个固定的next数组,它记录着字符串匹配过程中失配情况转载 2014-07-19 16:53:48 · 697 阅读 · 0 评论 -
POJ 2431 Expedition
链接:http://poj.org/problem?id=2431原创 2014-06-12 16:54:51 · 445 阅读 · 0 评论 -
POJ 3255 Roadblocks
链接:http://poj.org/problem?id=3255原创 2014-07-23 15:10:37 · 550 阅读 · 0 评论 -
HDU 3371 Connect the Cities
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3371跟畅通工程基本上一模一样。注意有chongbian原创 2014-07-26 16:28:33 · 514 阅读 · 0 评论 -
素数筛选法<单向链表实现>
#include using namespace std;struct note{ int data; note *next;};class listprime{private: note *head;public: listprime(int n); void Delete( note *p); void scan();原创 2014-06-21 01:30:58 · 798 阅读 · 0 评论 -
NYOJ 202 红黑树
链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=202原创 2014-09-10 16:07:15 · 571 阅读 · 0 评论 -
数据结构之树状数组
转载自:http://dongxicheng.org/structure/binary_indexed_tree/转载 2014-09-22 19:45:21 · 742 阅读 · 0 评论 -
LeetCode Valid Parentheses
链接: https://oj.leetcode.com/problems/valid-parentheses/括号匹配。用栈class Solution{ public: bool isValid(string s) { stack sta; int n=s.size(); for(int i=0;i<n;i++) { char t=s[原创 2015-02-14 17:01:36 · 637 阅读 · 0 评论