算法笔记
文章平均质量分 66
多角度思考一道题
smith日常碎碎念
公众号:smith日常碎碎念
展开
-
LeetCode28. Implement strStr() 字符串匹配
文章目录28.字符串匹配28. Implement strStr()暴力破解Rabin-Karp算法KMP算法BM算法(Boyer-Moore)Sunday算法28.字符串匹配28. Implement strStr()Implement strStr().Return the index of the first occurrence of needle in haystack, or ...原创 2020-04-05 10:08:44 · 233 阅读 · 0 评论 -
LeetCode 27.Remove Element 移除数组中的元素
文章目录移除元素27. Remove Element快慢双指针头尾双指针移除元素27. Remove ElementGiven an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for...原创 2020-03-01 14:51:08 · 249 阅读 · 0 评论 -
LeetCode 26.Remove Duplicates from Sorted Array 移除有序数组的重复元素
文章目录26.移除有序数组的重复元素26. Remove Duplicates from Sorted Array双指针法26.移除有序数组的重复元素26. Remove Duplicates from Sorted ArrayGiven a sorted array nums, remove the duplicates in-place such that each element ap...原创 2020-02-29 00:21:30 · 161 阅读 · 0 评论 -
LeetCode 25. Reverse Nodes in k-Group 以组的形式反转节点
文章目录25.以组的形式反转节点25. Reverse Nodes in k-Group尾插法头插法25.以组的形式反转节点25. Reverse Nodes in k-GroupGiven a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a po...原创 2020-02-26 23:07:40 · 294 阅读 · 0 评论 -
LeetCode 24.Swap Nodes in Pairs 成对交换链表节点
文章目录24.成对交换链表节点24. Swap Nodes in Pairs迭代法递归24.成对交换链表节点24. Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s node...原创 2020-02-25 16:01:29 · 200 阅读 · 0 评论 -
LeetCode 23.Merge k Sorted Lists 合并K个的有序链表
文章目录23.合并排序N个有序链表23. Merge k Sorted Lists直接合并分治法23.合并排序N个有序链表23. Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Inpu...原创 2020-02-24 19:55:45 · 263 阅读 · 0 评论 -
LeetCode22.Generate Parentheses 产生括号组合
22.产生括号组合22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", ...原创 2020-02-23 16:40:46 · 175 阅读 · 0 评论 -
LeetCode 19.Remove Nth Node From End of List 移除链表从后算起第几个元素
文章目录19.移除链表从后算起第几个元素19. Remove Nth Node From End of List两次遍历单次遍历19.移除链表从后算起第几个元素19. Remove Nth Node From End of ListGiven a linked list, remove the n-th node from the end of list and return its hea...原创 2020-02-17 21:41:20 · 99 阅读 · 0 评论 -
LeetCode17. Letter Combinations of a Phone Number电话号码组合
文章目录17. 电话号码组合17. Letter Combinations of a Phone Number深度优先遍历(DFS)直接拼接17. 电话号码组合17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible let...原创 2020-02-16 18:53:38 · 442 阅读 · 0 评论 -
LeetCode 18. 4Sum四数之和
18.4Sum 四数之和18. 4SumGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array whic...原创 2020-02-13 19:47:48 · 258 阅读 · 0 评论 -
LeetCode16. 3Sum Closest 三数之和改
16.3Sum Closest最接近目标值的三数之和3Sum ClosestGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integer...原创 2020-02-10 20:36:50 · 120 阅读 · 0 评论 -
LeetCode15.3Sum 三数之和
文章目录15. 3Sum 三数之和15. 3Sum双指针使用Map15. 3Sum 三数之和15. 3SumGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which give...原创 2020-02-08 11:57:49 · 157 阅读 · 0 评论 -
LeetCode 14. Longest Common Prefix最长公共子前缀
最长公共子前缀14. Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["fl...原创 2020-02-04 12:24:57 · 324 阅读 · 0 评论 -
LeetCode 13. Roman to Integer 罗马数字转阿拉伯数字
13. 罗马数字转阿拉伯数字13. Roman to IntegerLeetCode 12 的镜像问题Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X ...原创 2020-02-02 15:09:30 · 210 阅读 · 0 评论 -
LeetCode 12.Integer to Roman 阿拉伯数字转换为罗马数字
LeetCode 12.Integer to Roman 阿拉伯数字转换为罗马数字12. Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X ...原创 2020-02-01 20:26:22 · 266 阅读 · 0 评论 -
LeetCode 11. Container With Most Water 容器最大水容量
11. Container With Most Water 容器最大水容量11. Container With Most WaterGiven n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such t...原创 2020-01-30 10:37:42 · 197 阅读 · 0 评论 -
LeetCode 10.Regular Expression Matching 正则匹配
LeetCode 10 . Regular Expression Matching 正则匹配10. Regular Expression MatchingGiven an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.'.' Mat...原创 2020-01-29 10:13:17 · 227 阅读 · 0 评论 -
LeetCode 9. Palindrome Number 回文数字
LeetCode 9. Palindrome Number9.Palindrome NumberDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: tru...原创 2020-01-27 09:17:56 · 358 阅读 · 0 评论 -
LeetCode 8. String to Integer (atoi) 字符串转整形
LeetCode 8. String to Integer (atoi) 字符串转整形8. String to Integer (atoi)Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary unt...原创 2020-01-24 22:37:40 · 146 阅读 · 0 评论 -
LeetCode 7. Reverse Integer 反转整数
LeetCode 7. Reverse Integer 反转整数文章目录LeetCode 7. Reverse Integer 反转整数7. Reverse Integer直接反转7. Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output...原创 2020-01-22 21:06:21 · 356 阅读 · 0 评论 -
LeetCode 6. ZigZag ConversionZ字形转换
LeetCode 6. ZigZag ConversionZ字形转换文章目录LeetCode 6. ZigZag ConversionZ字形转换6. ZigZag Conversion直接跳转法(横着走)拉链法(竖着走)6. ZigZag ConversionThe string "PAYPALISHIRING" is written in a zigzag pattern on a giv...原创 2020-01-21 21:41:32 · 299 阅读 · 0 评论 -
LeetCode5. Longest Palindromic Substring 最长子回文串
最长子回文串5. Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note...原创 2020-01-19 23:18:22 · 149 阅读 · 0 评论 -
LeetCode4.Median of Two Sorted Arrays 求有序数组的中位数
Median of Two Sorted Arrays 有序数组的中位数4. Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run ...原创 2020-01-16 19:57:53 · 117 阅读 · 0 评论 -
LeetCode3. Longest Substring Without Repeating Characters 子字符串长度
文章目录字符串的长度3. Longest Substring Without Repeating Characters暴力破解滑动窗口(双指针法)滑动窗口改进字符串的长度3. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring withou...原创 2020-01-13 21:53:17 · 104 阅读 · 0 评论 -
Leetcode 2. Add Two Numbers 两数相加
Add Two Numbers 两数相加2. Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single...原创 2020-01-12 17:02:46 · 97 阅读 · 0 评论 -
Merge Two Sorted Lists 有序链表合并问题
Merge Two Sorted Lists 链表合并问题题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2-&...原创 2019-01-27 10:46:03 · 173 阅读 · 0 评论 -
Valid Parentheses 括号匹配问题
Valid Parentheses 括号匹配问题题目:Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be c...原创 2019-01-18 19:17:24 · 268 阅读 · 0 评论 -
算法笔记:编辑距离
算法笔记:编辑距离原题: 给出两个单词word1和word2,计算出将word1 转换为word2的最少操作次数。 你总共三种操作方法:插入一个字符删除一个字符替换一个字符给出 work1=”mart” 和 work2=”karma” 返回 3下面是两种思路实现,自顶向上方法和自顶向下方法1.自底向上方法实现不如将问题简化下,化成规模比较小的问题。 首先,我们先考虑两个空串,那么当然原创 2017-08-29 15:01:06 · 371 阅读 · 0 评论 -
算法笔记:二进制数有多少个1
32位的整数的二进制数表示有多少个1?原创 2017-07-25 17:05:21 · 1006 阅读 · 0 评论