• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
frankM
天下武功,唯快不破。
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

随笔分类 -  数据结构

 
LeetCode Remove Duplicates from Sorted Array
摘要:链接:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/把有序数组中重复的元素删除,并返回删除后的数组长度。考虑直接插入排序的过程,如果遇见重复的元素,直接抛弃,判断下一个元素。由于数组本身有序,所以,时间复杂的... 阅读全文
posted @ 2015-02-23 23:42 frankM 阅读(91) 评论(0) 推荐(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(... 阅读全文
posted @ 2015-02-14 17:01 frankM 阅读(154) 评论(0) 推荐(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 lis... 阅读全文
posted @ 2015-02-12 00:58 frankM 阅读(133) 评论(0) 推荐(0)
LeetCode 5 最长回文子串 Manacher线性算法
摘要:题目链接:https://oj.leetcode.com/problems/longest-palindromic-substring/回文串即正向反向序列都一样的连续序列 如abba,abcba...为了统一回文串的偶数情况和奇数情况,可以向串中插入不相关的字符,例如abba->#a#b#b#a#... 阅读全文
posted @ 2015-01-26 12:19 frankM 阅读(220) 评论(0) 推荐(0)
LeetCode Longest Substring Without Repeating Characters
摘要:链接: https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/字符串中最长连续不重复子序列,用JAVA中的哈希表比较方便public class Solution { public int... 阅读全文
posted @ 2015-01-22 23:50 frankM 阅读(124) 评论(0) 推荐(0)
Add Two Numbers
摘要:链接:https://oj.leetcode.com/problems/add-two-numbers/链表的大数加法/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode ... 阅读全文
posted @ 2015-01-20 20:08 frankM 阅读(123) 评论(0) 推荐(0)
LeetCode Swap Nodes in Pairs
摘要:链接:https://oj.leetcode.com/problems/swap-nodes-in-pairs/交换链表相邻的节点的位置/** * Definition for singly-linked list. * struct ListNode { * int val; * ... 阅读全文
posted @ 2015-01-18 14:24 frankM 阅读(128) 评论(0) 推荐(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 majo... 阅读全文
posted @ 2015-01-16 20:02 frankM 阅读(115) 评论(0) 推荐(0)
LeetCode Evaluate Reverse Polish Notation
摘要:链接: https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/后缀表达式求值class Solution{ public: int evalRPN(vector &tokens) { stack stk; in... 阅读全文
posted @ 2015-01-01 10:47 frankM 阅读(138) 评论(0) 推荐(0)
LeetCode Merge Two Sorted Lists
摘要:链接: https://oj.leetcode.com/problems/merge-two-sorted-lists/题目要去把两个有序的链表合并,并且合并后的链表依然有序./** * Definition for singly-linked list. * struct ListNode { *... 阅读全文
posted @ 2014-12-24 22:31 frankM 阅读(89) 评论(0) 推荐(0)
LeetCode Rotate List
摘要:链接: https://oj.leetcode.com/problems/rotate-list//** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next... 阅读全文
posted @ 2014-12-05 21:39 frankM 阅读(112) 评论(0) 推荐(0)
LeetCode Reorder List
摘要:链接: https://oj.leetcode.com/problems/reorder-list/空间复杂度为O(n),时间复杂度为 O(n)的代码:/** * Definition for singly-linked list. * struct ListNode { * int val... 阅读全文
posted @ 2014-12-04 13:55 frankM 阅读(137) 评论(0) 推荐(0)
LeetCode Partition List
摘要:链接: https://oj.leetcode.com/problems/partition-list/双重指针....../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNo... 阅读全文
posted @ 2014-11-27 17:26 frankM 阅读(132) 评论(0) 推荐(0)
LeetCode Convert Sorted Array to Binary Search Tree
摘要:链接: https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/把一个有序数组转换成一棵AVL树/** * Definition for binary tree * struct TreeNode { *... 阅读全文
posted @ 2014-11-04 21:35 frankM 阅读(148) 评论(0) 推荐(0)
数据结构之树状数组
摘要:转载自:http://dongxicheng.org/structure/binary_indexed_tree/1、概述树状数组(binary indexed tree),是一种设计新颖的数组结构,它能够高效地获取数组中连续n个数的和。概括说,树状数组通常用于解决以下问题:数组{a}中的元素可能不... 阅读全文
posted @ 2014-09-22 19:45 frankM 阅读(279) 评论(0) 推荐(0)
 

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3