
算法
文章平均质量分 57
michael_ma_
一只大菜鸟。
展开
-
【DP】矩阵链乘法
-----代码明天上传。原创 2014-11-13 21:59:52 · 793 阅读 · 0 评论 -
【leetcode】 Single_Number_II
问题描述:Given an array of integers, every element appears three times except for one. Find that single one.解法:设置一个32为的数组,第i位的数字对应元素出现的次数。我们把 第 ith个位置上所有数字的和对3取余,那么只会有两个结果 0 或 1.然后计算 public int si原创 2015-03-03 23:32:49 · 404 阅读 · 0 评论 -
常用的排序算法以及实现
排序与查找是面试中最容易遇到的两类题,现在总结一下各种排序算法以及实现:1.直接插入排序2.希尔排序3.冒泡排序4.快速排序5.简单选择排序6.堆排序7.二路归并排序8.桶排序原创 2015-03-09 20:10:22 · 360 阅读 · 0 评论 -
【leetcode】 ZigZag Conversion
问题描述: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 A H NA P L原创 2015-03-19 22:47:49 · 373 阅读 · 0 评论 -
处理hash冲突的常见办法
1.开放定址法2.拉链发3.公共溢出区原创 2015-03-16 22:31:53 · 847 阅读 · 0 评论 -
【leetcode】Longest Substring Without Repeating Characters
问题描述:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2015-03-16 22:29:04 · 450 阅读 · 0 评论 -
【leetcode】 Reverse Integer
问题描述:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321问题考虑:1.考虑逆转越界的问题其余思路常规题解法~ public int reverse(int x) { int temp=0; int si原创 2015-03-16 23:02:07 · 491 阅读 · 0 评论 -
【leetcode】 Two_Sum
问题描述:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target原创 2015-03-10 21:34:53 · 490 阅读 · 0 评论 -
【leetcode】 Maximum Gap
问题描述:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 eleme原创 2015-03-19 00:10:19 · 531 阅读 · 0 评论 -
【leetcode】 Palindrome Number
问题描述:Determine whether an integer is a palindrome. Do this without extra space.问题思考:由于不能使用额外的空间:这里我认为它的意思是不能把int转为String那样做。所以最直接的想法就是说:将数字分解逆序构造一个新的数字,最后判断。但是逆序的容易产生溢出问题,考虑到回文的特殊性,只需要判断一半就行了。比原创 2015-03-18 17:40:39 · 435 阅读 · 0 评论 -
最长递增子序列
这道题是编程之美的2.16.这里编程之美在用DP讲的时候思路还是比较清晰的。时间复杂度为 N^2,看下代码;public int list(int[] A){ int sum = 0; int[] LIS = new int[A.length]; for(int i=0;i<A.length;i++){ LIS[i]=1; for(int j原创 2015-04-19 19:55:11 · 393 阅读 · 0 评论 -
【leetcode】 Best Time to Buy and Sell Stock II
问题描述:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, b原创 2015-04-25 16:33:20 · 345 阅读 · 0 评论 -
【leetcode】 Best Time to Buy and Sell Stock
问题描述:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the st原创 2015-04-25 16:42:40 · 352 阅读 · 0 评论 -
【leetcode】 Best Time to Buy and Sell Stock III
问题描述:Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:Yo原创 2015-04-25 16:45:56 · 399 阅读 · 0 评论 -
【leetcode】 Edit Distance
问题描述: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a原创 2015-04-27 08:59:35 · 399 阅读 · 0 评论 -
【leetcode】 Regular Expression Matching
题目:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire inp原创 2015-05-25 08:47:32 · 458 阅读 · 0 评论 -
【leetcode】 Insertion_Sort_List
问题描述:Sort a linked list using insertion sort.解析:插入排序,常规算法。 public ListNode insertionSortList(ListNode head) { ListNode temp=null; ListNode root=new ListNode(Integer.MIN_VALUE);原创 2015-03-03 23:31:26 · 475 阅读 · 0 评论 -
【leetcode】 Linked_List_Cycle_II
问题描述:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?解析:网上解析很多,不一一赘述.public ListNode dete原创 2015-03-01 20:21:55 · 421 阅读 · 0 评论 -
【leetcode】 Majority_Element
题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2015-03-01 13:47:30 · 488 阅读 · 0 评论 -
【DP】最长公共子序列。
------代码整理中。原创 2014-11-27 10:42:25 · 405 阅读 · 0 评论 -
【DP】 最长公共回文子序列
问题描述:给一个字符串,找出它的最长的回文子序列的长度。例如,如果给定的序列是“BBABCBCAB”,则输出应该是7,“BABCBAB”是在它的最长回文子序列。 “BBBBB”和“BBCBB”也都是该字符串的回文子序列,但不是最长的。原创 2014-12-03 11:27:29 · 737 阅读 · 0 评论 -
【leetcode】Intersection of Two Linked Lists
问题描述:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: /** * A: a1 → a2原创 2014-12-29 16:42:32 · 471 阅读 · 0 评论 -
【leetcode】Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest pro原创 2014-12-08 21:57:20 · 485 阅读 · 0 评论 -
【leetcode】Linked List Cycle
问题描述:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 思路:1.遍历链表,比较set中是否包含节点的地址,如果包含说明是有环,如果不包含,则将地址存入到set中;缺点:leetcdoe显示time原创 2015-01-05 22:12:32 · 487 阅读 · 0 评论 -
【leetcode】Evaluate Reverse Polish Notation
问题:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:["2", "1", "原创 2015-01-06 10:21:41 · 424 阅读 · 0 评论 -
【leetcode】Word Break
------------------代码周末传。原创 2014-12-30 16:13:13 · 471 阅读 · 0 评论 -
【leetcode】 Find Minimum in Rotated Sorted Array
问题:Suppose a sorted array 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).Find the minimum element.You may assume no duplicate exists in the原创 2015-01-06 09:50:49 · 396 阅读 · 0 评论 -
【leetcode】 Factorial_Trailing_Zeroes
题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity. /* * 考虑如下情况: * 计算23!的末尾有多少0 * 思路: * 如果要末尾出现0,则原创 2015-02-28 18:26:05 · 378 阅读 · 0 评论 -
【leetcode】 Add Two Numbers
问题描述:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2015-03-14 00:27:53 · 348 阅读 · 0 评论 -
【leetcode】 Compare_Version_Numbers
问题描述:If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and contain only digits and the . character.The .原创 2015-02-28 18:19:47 · 330 阅读 · 0 评论 -
【leetcode】 Excel_Sheet_Column_Number
问题描述:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2015-02-28 18:22:11 · 376 阅读 · 0 评论 -
【leetcode】 Excel_Sheet_Column_Title
题目 :Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 解析:常规原创 2015-02-28 18:24:15 · 433 阅读 · 0 评论 -
【leetcode】 Largest_Number
问题描述:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be原创 2015-03-01 22:48:22 · 352 阅读 · 0 评论 -
【leetcode】 Fraction_to_Recurring_Decimal
问题描述:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parenthese原创 2015-02-28 22:01:49 · 424 阅读 · 0 评论 -
【leetcode】 Maximum Subarray
题目描述: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,原创 2015-05-25 09:51:33 · 399 阅读 · 0 评论