c++/c
文章平均质量分 67
xw_njust_ecjtu
沉淀
展开
-
N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-06-23 21:42:40 · 571 阅读 · 0 评论 -
Container 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 at (i, ai) and (i, 0). Fin原创 2014-07-01 16:36:08 · 474 阅读 · 0 评论 -
Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return原创 2013-12-20 21:37:24 · 607 阅读 · 0 评论 -
Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found原创 2014-07-02 10:32:21 · 456 阅读 · 0 评论 -
Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2014-07-02 10:53:20 · 468 阅读 · 0 评论 -
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[ [2], [3,4], [原创 2014-07-02 15:50:23 · 911 阅读 · 0 评论 -
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 3. Fo原创 2014-07-01 15:46:20 · 445 阅读 · 0 评论 -
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2014-07-02 11:19:01 · 505 阅读 · 0 评论 -
Largest Rectangle in Histogram -- 待看
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o原创 2014-07-03 15:25:35 · 479 阅读 · 0 评论 -
Search 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).You are given a target value to search. If found in the array retur原创 2014-01-02 21:52:37 · 602 阅读 · 0 评论 -
Jump Game II
//dp 问题 ,dp[i] = min(dp[j])+1;(0 i的情况(即能覆盖i) ) //dp[i] 为0-i的的最少步数 int jump_game(int *a,int n) { if (a == NULL || n <= 0) { return 0; } int *count = new int [n];原创 2014-06-30 17:16:39 · 467 阅读 · 0 评论 -
Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2014-06-30 17:05:14 · 481 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2013-12-05 20:13:11 · 670 阅读 · 0 评论 -
Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-06-23 20:11:25 · 558 阅读 · 0 评论 -
Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-06-25 21:18:10 · 539 阅读 · 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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-06-25 22:45:09 · 464 阅读 · 0 评论 -
Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina原创 2014-06-25 20:09:25 · 419 阅读 · 0 评论 -
Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb原创 2014-06-25 16:42:33 · 452 阅读 · 0 评论 -
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 day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.此题看清题,最多俩次jiaoy原创 2014-06-30 21:27:19 · 480 阅读 · 0 评论 -
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, buy on原创 2014-06-30 21:13:56 · 449 阅读 · 0 评论 -
Catalan数计算及应用
转自:http://blog.csdn.net/wuzhekai1985/article/details/6764858转载 2014-06-30 09:51:25 · 501 阅读 · 0 评论 -
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 stock),原创 2014-06-30 21:06:50 · 507 阅读 · 0 评论 -
Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.一原创 2014-07-24 10:55:46 · 516 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2014-07-04 15:07:32 · 450 阅读 · 0 评论 -
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 word:原创 2014-07-03 20:39:17 · 553 阅读 · 0 评论 -
Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-07-10 10:46:12 · 498 阅读 · 0 评论 -
Sort Colors
Given 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 use the integers原创 2014-07-10 17:16:32 · 527 阅读 · 0 评论 -
Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.此题已处理的了,回文。首先原创 2014-07-09 17:34:37 · 512 阅读 · 0 评论 -
Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-07-09 16:36:37 · 552 阅读 · 0 评论 -
华为机试-2014
题目大意:有字符串表示的一个四则运算表达式,要求计算出该表达式的正确数值。四则运算即:加减乘除"+-*/",另外该表达式中的数字只能是1位(数值范围0~9)。另若有不能整除的情况,按向下取整处理,eg: 8/3得出值为2。 若有字符串"8+7*2-9/3",计算出其值为19。本人使用的是《渐降解析法》---》由于使用c语言,没有直接的栈可以使用,所以个人感觉机原创 2013-09-09 20:47:12 · 947 阅读 · 0 评论 -
LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2013-11-24 18:44:37 · 753 阅读 · 0 评论 -
二叉树中两个节点的最近公共父节点
二叉树中两个节点的最近公共父节点,转载 2014-09-02 20:51:17 · 3252 阅读 · 0 评论 -
柔性数组
柔性数组数组大小待定的数组(可变)C语言中结构体的最后一个元素可以是大小可变的数组 (只能放在结构体中,表明一种符号)C语言中可以由结构体产生柔性数组int size[0]这种在C/C++是不允许的,但是在结构中确实可以使用的(C99标准)。经过查看资料,知道这种可变数组被称为柔性数组。在通信行业这种代码司空见惯。柔性数组的结构如何只能堆上生成,C99的扩展,简而言之就是一个在struct结原创 2016-08-01 11:56:11 · 397 阅读 · 0 评论 -
leetcode 目录--更新....
//注:很多代码未加入,内存分配是否成功的判断!//二维数组分配问题需注意,leetcode 可以接受变量的a[m][n],自己实现需,int **a = new int [m];for(){a[i] = new int[n]} -- 释放类似1、String to Integer (atoi)2、 Populating Next Right Pointers in Each Nod...原创 2013-11-24 19:23:44 · 1928 阅读 · 0 评论 -
Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did原创 2014-07-09 22:59:14 · 479 阅读 · 0 评论 -
两个人抛硬币来决定谁吃这个苹果,先抛到正面者吃。问先抛者吃到苹果的概率是多少?
A和B2人投硬币,正面A得1元,反面B得一元.起始时A有1元,B有100元. 游戏持续进行,直到其中1人破产才终止.1.如果硬币正反概率相同,游戏的期待长度(expected duration)是几次投掷? 2.如果硬币是不公正的,正面概率为P,反面概率为Q.(P+Q=1), 那么游戏的期待长度(expectedduration)是几次投掷?目前认为只有奇数次才可能破产。原创 2014-07-31 22:39:51 · 21601 阅读 · 2 评论 -
4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2014-07-07 21:54:03 · 484 阅读 · 0 评论 -
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-07-04 16:38:41 · 508 阅读 · 0 评论 -
Two Sum
注释的部分是普通解法o(n^2)排序使数组是有序的,O(n)的时间复杂度就可以解决了,此题注意小标即可!指针从俩边向中间靠拢!#includestruct num_type { int val; int pos; }; bool cmp(num_type a,num_type b) { return a.val原创 2013-11-23 14:43:33 · 720 阅读 · 0 评论 -
3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2014-07-07 10:59:42 · 542 阅读 · 0 评论