算法分析与设计
文章平均质量分 58
xiasilo
一条咸鱼,什么都没有留下……
展开
-
11. Contain with most water
11 contain with most water Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is a...原创 2017-09-24 19:36:15 · 667 阅读 · 0 评论 -
91. Decode Ways
91 Decode Ways A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an en...原创 2017-11-05 22:24:35 · 138 阅读 · 0 评论 -
6. ZigZag Conversion
6. 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)...原创 2017-12-10 15:01:55 · 248 阅读 · 0 评论 -
135. Candy
135 Candy There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child m...原创 2017-12-03 21:53:58 · 147 阅读 · 0 评论 -
312. Burst Balloons
312. Burst Balloons Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst ball...原创 2017-11-27 00:25:49 · 147 阅读 · 0 评论 -
639. Decode Ways II
639. Decode Ways II A message containing letters from A-Z is being encoded to numbers using the following mapping way: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Bey...原创 2017-12-24 21:25:38 · 150 阅读 · 0 评论 -
82.Remove Duplicates from Sorted List II
82. Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given...原创 2017-12-17 16:55:18 · 155 阅读 · 0 评论 -
证明STINGY SAT是NP-complete问题
8.3.STINGY SAT :given a set of clauses and an integer k,find a satisfying assignment in which at most k variables are true. Prove that STING SAT is NP-complete.原创 2018-01-02 14:32:19 · 956 阅读 · 0 评论 -
调整数组顺序使奇数位于偶数前面
题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。函数原型:void reOrderArray(vector<int> &array);想在O(n)的时间复杂度的前提下完成排序,容易想到的排序方法很难保证奇数和奇数、偶数和...原创 2018-05-17 17:43:57 · 160 阅读 · 0 评论 -
442. Find All Duplicates in an Array
442. 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...原创 2017-11-19 22:08:45 · 151 阅读 · 0 评论 -
136. Single Number
136.Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you impl...原创 2017-11-12 22:43:18 · 159 阅读 · 0 评论 -
链表加法
You 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 digit. Add the two numbers and retur...原创 2017-09-17 17:30:18 · 517 阅读 · 0 评论 -
34. Search for a Range
34 Search for a Range Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the...原创 2017-09-17 19:20:24 · 153 阅读 · 0 评论 -
Two Sum
Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may n...原创 2017-09-10 12:33:24 · 150 阅读 · 0 评论 -
120. Triangle
120. Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ ...原创 2017-10-07 14:48:38 · 193 阅读 · 0 评论 -
7. Reverse Integer
7. Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321这题的思路很简单,就是现将整数x的每一位数提取出来,之后倒序乘上10的对应次方然后相加,再判断是否越界就行。无论正负对计算结果没有影响。 参考代码如...原创 2017-10-01 22:56:32 · 137 阅读 · 0 评论 -
322. Coin Change
322. Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. I...原创 2017-10-29 21:47:01 · 172 阅读 · 0 评论 -
79. Word Search
79. Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those hori...原创 2017-10-23 20:21:20 · 131 阅读 · 0 评论 -
476. Number Complement
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 guarante...原创 2017-10-15 16:29:48 · 154 阅读 · 0 评论 -
minimum-depth-of-binary-tree
题目描述 Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.首先我们注意到,二叉树的深度从根结点往下数到叶子结点...原创 2018-05-13 01:03:53 · 148 阅读 · 0 评论