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

随笔分类 -  leetcode

 
LeetCode Remove Element
摘要:链接:https://oj.leetcode.com/problems/remove-element/跟上一道题很像,设置两个指针根据情况交替前进就可以。代码很简单class Solution{ public: int removeElement(int A[],int n,int elem){ ... 阅读全文
posted @ 2015-02-26 14:00 frankM 阅读(89) 评论(0) 推荐(0)
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 Generate Parentheses
摘要:链接:https://oj.leetcode.com/problems/generate-parentheses/好几天没做题了,一直在看java ee。。看来我在回溯,递归方面还是相当的弱啊。。。最后还是参考的别人的思路class Solution{ public: vector generat... 阅读全文
posted @ 2015-02-20 19:43 frankM 阅读(127) 评论(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 4sum
摘要:链接:https://oj.leetcode.com/problems/4sum/一种方法是跟3sum一样,使用头尾指针交替移动,时间复杂度为O(n3),空间复杂度为O(1),注意去重class Solution{ public: vector >fourSum(vector &num,int t... 阅读全文
posted @ 2015-02-10 00:19 frankM 阅读(145) 评论(0) 推荐(0)
LeetCode Letter Combinations of a Phone Number
摘要:链接:https://oj.leetcode.com/problems/letter-combinations-of-a-phone-number/递归算法:class Solution{ public: vector letterCombinations(str... 阅读全文
posted @ 2015-02-06 01:37 frankM 阅读(98) 评论(0) 推荐(0)
LeetCode 3Sum Closest
摘要:链接:https://oj.leetcode.com/problems/3sum-closest/跟3-sum的思路是一样的。根据sum与target的大小关系,分别移动数组两端的“指针”,同时记录sum与target最小的距离class Solution {public: int three... 阅读全文
posted @ 2015-02-02 22:33 frankM 阅读(105) 评论(0) 推荐(0)
LeetCode Integer to Roman
摘要:链接: https://oj.leetcode.com/problems/integer-to-roman/题目上已经说最大出现的整型值为3999,这样就很简单了。class Solution{ public: string intToRoman(int num) { string ans;... 阅读全文
posted @ 2015-01-31 20:42 frankM 阅读(110) 评论(0) 推荐(0)
Container With Most Water
摘要:链接: https://oj.leetcode.com/problems/container-with-most-water/尺取法,从两端向中间缩进class Solution{ public: int maxArea(vector &height) //尺取法 { int L=0; ... 阅读全文
posted @ 2015-01-29 15:02 frankM 阅读(127) 评论(0) 推荐(0)
LeetCode ZigZag Conversion
摘要:链接: https://oj.leetcode.com/problems/zigzag-conversion/题意为:把字符串按如下规则排列AGMBFHLNCEIK:DJ:输出按行顺序:AGMBFHLNCEIKDJ剩下的就是通过字符的坐标计算在字符串中的位置了class Solution{ publ... 阅读全文
posted @ 2015-01-28 01:34 frankM 阅读(137) 评论(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)
 

公告


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