![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
李文区
这个作者很懒,什么都没留下…
展开
-
欧几里得最大公约数两种算法
递归:int f(int m, int n) { return n == 0 ? m : f(n, m % n); }非递归:int f(int m, int n) { int r = n; do { n = r; r = m % n; m = n; } while (r > 0); return n; }原创 2016-07-16 07:44:10 · 349 阅读 · 0 评论 -
Edit Distance 算法实现及其设计原理
题目: Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitted on a word: Insert a character Delete a ...原创 2019-01-02 23:38:59 · 589 阅读 · 0 评论 -
Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of t...原创 2018-08-02 16:55:39 · 245 阅读 · 0 评论 -
Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found ...原创 2018-07-30 14:25:28 · 143 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1: Input: "(()" Output: 2 Explanation: The longest valid...原创 2018-07-30 11:10:51 · 140 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4...原创 2018-06-11 00:10:09 · 104 阅读 · 0 评论 -
Divide Two Integers
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division should ...原创 2018-06-12 08:16:33 · 114 阅读 · 0 评论 -
Generate Parentheses的解法
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "...原创 2018-04-01 20:53:47 · 209 阅读 · 0 评论 -
ZigZag Conversion
这题就很简单了,4分钟搞定 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P原创 2017-12-26 15:26:04 · 104 阅读 · 0 评论 -
Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer.原创 2017-12-26 13:34:22 · 108 阅读 · 0 评论 -
Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1,原创 2017-12-25 15:53:31 · 140 阅读 · 0 评论