ACM
文章平均质量分 75
小灰灰52309
图像处理方向,大家多多交流
展开
-
最大公约数最小公倍数
求最大公约数和最小公倍数假设有两个数a和b,求a,b的最大公约数和最小公倍数实际上是一个问题,得出这两个数的最大公约数就可以算出它们的最小公倍数。最小公倍数的公式是 a*b/mm为最大公约数因为a=m*i; b=m*j;最小公倍数为 m*i*j那么,下面就开始计算a和b的最大公约数。更相损减法:《九章算術·方田》作分數約簡時,转载 2016-08-19 12:11:33 · 965 阅读 · 0 评论 -
POJ
题目链接:http://poj.org/problem?id=1753题解:状态压缩bfs()方格为4*4所以状态最多有2^16int 可以表示,0为全黑,65535为全白从起始状态开始bfs过程中判断是否搜到0或65535关键是进行状态的转换,使用亦或操^,每次改变该位的数字,到相反。其中0表示黑,1表示白代码如下:#include#include#inclu转载 2016-08-19 12:13:35 · 197 阅读 · 0 评论 -
leedcode ZigZag Conversion
ZigZag ConversionThe 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 legibi原创 2016-08-20 14:01:31 · 168 阅读 · 0 评论 -
leedcode Ransom Note
Ransom Note Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the原创 2016-08-20 14:15:08 · 185 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock本题有一共有四中问题1. Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one tra原创 2017-04-10 16:17:07 · 217 阅读 · 0 评论 -
Longest Word in Dictionary through Deleting
524. Longest Word in Dictionary through Deleting Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given s原创 2017-04-11 10:57:17 · 204 阅读 · 0 评论 -
476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of原创 2017-04-11 19:52:20 · 177 阅读 · 0 评论 -
Complex Number Multiplication
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i"Out原创 2017-04-12 10:44:34 · 164 阅读 · 0 评论 -
Find Largest Value in Each Tree Row
Find Largest Value in Each Tree Row题目:You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5原创 2017-04-12 15:34:24 · 159 阅读 · 0 评论 -
Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without ex原创 2017-04-12 16:17:49 · 218 阅读 · 0 评论 -
Convert BST to Greater Tree
Convert BST to Greater Tree题目:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater原创 2017-04-12 16:40:22 · 147 阅读 · 0 评论 -
Detect Capital
题目:Detect CapitalGiven a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases hol原创 2017-04-12 17:15:58 · 222 阅读 · 0 评论 -
Diagonal Traverse
Diagonal TraverseGiven a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.Example:Input:[ [ 1, 2, 3 ], [原创 2017-04-17 16:45:12 · 310 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array
题目:Find Minimum in Rotated Sorted ArraySuppose 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).原创 2017-04-13 16:25:32 · 139 阅读 · 0 评论 -
First Missing Positive
题目:First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run原创 2017-04-13 16:50:58 · 124 阅读 · 0 评论 -
Minimum Moves to Equal Array Elements II
题目:Minimum Moves to Equal Array Elements IIGiven a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected elem原创 2017-04-13 17:44:23 · 189 阅读 · 0 评论 -
Total Hamming Distance
Total Hamming DistanceThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance原创 2017-04-18 10:08:23 · 162 阅读 · 0 评论 -
Add Two Numbers II
Add Two Numbers IIYou are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the原创 2017-04-18 15:11:08 · 171 阅读 · 0 评论 -
Base 7
Base 7Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"解析:简单题,求一个数的七进制代码:class Solution {p原创 2017-04-18 15:28:57 · 226 阅读 · 0 评论 -
Sort Characters By Frequency
题目:Sort Characters By FrequencyGiven a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice wh原创 2017-04-14 10:59:41 · 194 阅读 · 0 评论 -
Minimum Time Difference
Minimum Time DifferenceGiven a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.Example 1:Input:原创 2017-04-18 19:39:50 · 258 阅读 · 0 评论 -
Number of Boomerangs
Number of BoomerangsGiven n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance betwe原创 2017-04-19 10:25:45 · 185 阅读 · 0 评论 -
Reverse String II
Reverse String IIGiven a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters le原创 2017-04-19 10:40:34 · 208 阅读 · 0 评论 -
Student Attendance Record I
Student Attendance Record IYou are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' :原创 2017-04-19 10:55:00 · 731 阅读 · 0 评论 -
Diameter of Binary Tree
Diameter of Binary TreeGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath between any two nodes in原创 2017-04-19 13:25:16 · 156 阅读 · 0 评论 -
Predict the Winner
Predict the WinnerGiven an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on.原创 2017-04-19 14:55:06 · 182 阅读 · 0 评论 -
Ones and Zeroes
Ones and ZeroesIn the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s resp原创 2017-05-02 09:47:51 · 186 阅读 · 0 评论 -
Sort Colors
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will原创 2017-05-02 10:26:14 · 154 阅读 · 0 评论 -
Different Ways to Add Parentheses
Different Ways to Add ParenthesesGiven a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid o原创 2017-04-19 22:41:12 · 163 阅读 · 0 评论 -
Ugly Number
Ugly Number IIWrite a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the se原创 2017-05-02 14:42:45 · 192 阅读 · 0 评论 -
Permutation in String
Permutation in StringGiven two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substrin原创 2017-05-02 14:59:41 · 525 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate ea原创 2017-05-02 15:19:04 · 230 阅读 · 0 评论 -
Unique Binary Search Trees II
Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return原创 2017-04-20 10:26:49 · 152 阅读 · 0 评论 -
Serialize and Deserialize Binary Tree
Serialize and Deserialize Binary TreeSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmi原创 2017-05-10 18:56:23 · 164 阅读 · 0 评论 -
Search in Rotated Sorted Array II
Search in Rotated Sorted Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array原创 2017-05-10 20:39:29 · 203 阅读 · 0 评论 -
Contiguous Array
Contiguous ArrayGiven a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0, 1] is the longest co原创 2017-05-02 16:09:54 · 197 阅读 · 0 评论 -
Game of Life
Game of LifeAccording to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Giv原创 2017-05-02 16:40:02 · 199 阅读 · 0 评论 -
Zuma Game
Zuma GameThink about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.Each time, you may原创 2017-05-02 17:58:45 · 455 阅读 · 0 评论 -
Relative Ranks
Relative RanksGiven scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".原创 2017-04-17 11:26:04 · 160 阅读 · 0 评论 -
01 Matrix
01 MatrixGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:原创 2017-05-11 10:46:34 · 214 阅读 · 0 评论