- 博客(319)
- 收藏
- 关注
原创 报数(华为内部oj)
报数 Time: 00 Hour 04 Minute 32 Second Description: 有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出,问最后留下的那位是原来第几号。Input:使用标准输入stdio.多行,每行一组数据。Output:多行,每行对应求和结果。Sample Input:3Sample
2017-09-14 14:35:47
1192
原创 (转)问题:假设一个没有头指针的单链表。一个指针指向此单链表中间的一个节点(既不是第一个,也不是最后一个节点),请将该节点从单链表中删除。
问题:假设一个没有头指针的单链表。一个指针指向此单链表中间的一个节点(既不是第一个,也不是最后一个节点),请将该节点从单链表中删除。p->data = p->next->data;p->next = p->next->next;firee(p->next); 链表结点定义如下:struct ListNode{ int
2016-10-17 21:00:48
1434
原创 LeetCode 题目总结/分类(转载,做了一些标记)
利用堆栈:(5)http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problems/longest-valid-parentheses/ (也可以用一维数组,贪心)http://oj.leetcode.com/problems/valid-parenthes
2016-10-11 14:33:17
930
原创 88. Merge Sorted Array(二刷,一种简洁的写法)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit
2016-10-11 14:05:44
413
原创 29. Divide Two Integers(二刷)
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Subscribe to see which companies asked this questionac代码:class
2016-10-11 10:19:42
331
原创 42. Trapping Rain Water(二刷)
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2016-10-09 23:07:24
342
原创 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)P A H NA P L S I
2016-10-06 23:53:40
253
原创 43. Multiply Strings(string模拟大数乘法)
Given two numbers represented as strings, return multiplication of the numbers as a string.Note:The numbers can be arbitrarily large and are non-negative.Converting the input string to integ
2016-10-06 22:19:42
351
转载 从头到尾彻底理解KMP
转自:http://blog.youkuaiyun.com/v_july_v/article/details/7041827从头到尾彻底理解KMP作者:July时间:最初写于2011年12月,2014年7月21日晚10点 全部删除重写成此文,随后的半个多月不断反复改进。后收录于新书《编程之法:面试和算法心得》第4.
2016-10-06 17:18:22
416
原创 98. Validate Binary Search Tree(中序遍历判断BST)
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2016-10-06 16:46:14
424
原创 4. 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 =
2016-10-06 15:28:45
256
原创 93. Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2016-10-05 21:31:18
342
原创 atoi和stoi
vs环境下:stoi函数默认要求输入的参数字符串是符合int范围的[-2147483648, 2147483647],否则会runtime error。atoi函数则不做范围检查,若超过int范围,则显示-2147483648(溢出下界)或者2147483647(溢出上界)。stoi头文件:,c++函数atoi头文件:,c函数test:#incl
2016-10-05 20:57:49
13097
原创 95. Unique Binary Search Trees II
Given 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 all 5 unique BST's shown below. 1
2016-10-05 20:12:56
295
原创 17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st
2016-10-05 17:17:56
418
原创 37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2016-10-05 11:13:39
304
原创 40. 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
2016-10-05 10:17:56
216
原创 关于STL中vector使用unique()去重的问题
STL中Unique函数的作用是去除相邻重复元素#include#include#includeusing namespace stdint main(){int a[10] = {7,4,1,7,4,1,7,4,1,0};sort(a,a+10);//小到大vectorver(a,a+10);vector::iterator iter = un
2016-10-05 09:45:58
8473
原创 22. Generate Parentheses(dfs,括号的可能排列数)
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:[ "((()))", "(()())", "(())()", "()(())
2016-10-04 23:41:11
267
原创 76. Minimum Window Substring(贪心,滑动窗口实现,hard)
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN
2016-10-03 20:06:02
688
原创 123. Best Time to Buy and Sell Stock III(贪心,hard)
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.Note:You ma
2016-10-03 15:39:48
222
原创 122. 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
2016-10-03 13:03:48
281
原创 45. Jump Game II(贪心)(hard)
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.Your goal i
2016-10-03 12:33:40
236
原创 55. 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
2016-10-03 11:25:05
295
原创 131. Palindrome Partitioning(递归)
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa","b"],
2016-10-02 18:55:46
272
原创 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2016-10-01 16:24:53
246
原创 140. Word Break II(dp,字典匹配,并输出所有匹配结果,即保存dp路径)(继续理解,重刷)
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2016-10-01 15:07:04
410
原创 leetcode 139. Word Break(dp,字典匹配)
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"
2016-09-30 23:26:51
230
原创 leetcode 72. 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:
2016-09-30 21:42:56
294
原创 leetcoed90. Subsets II(集合子集去重)
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a sol
2016-09-30 19:40:57
490
原创 leetcode 78. Subsets(DFS找集合的全部子集)
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],
2016-09-30 10:59:44
607
转载 kmp算法
转自:http://kb.cnblogs.com/page/176818/字符串匹配的KMP算法作者: 阮一峰 发布时间: 2013-08-28 17:12 阅读: 97278 次 推荐: 185 原文链接 [收藏] 字符串匹配是计算机的基本任务之一。 举例来说,有一个字符串"BBC ABCDAB ABCDABCDA
2016-09-24 09:55:13
278
原创 hdu2045 有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法.
描述:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法.以上就是著名的RPG难题.Input输入数据包含多个测试实例,每个测试实例占一行,由一个整数N组成,(0Output对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行。
2016-09-23 21:17:02
7122
原创 48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Subscribe to see which companies asked this que
2016-09-23 10:59:06
180
原创 将数组中所有小于或等于0的元素都放在数组前面,大于0的元素放在数组后面。要求时间复杂度为o(n)
【编程】对于一个给定的整形数组int array[n]。编程实现:将数组中所有小于或等于0的元素都放在数组前面,大于0的元素放在数组后面。要求时间复杂度为o(n) void Divide(int array[], int n) { int i = 0; for (int j = 0; j { if (array[j] { int temp;
2016-09-20 20:28:55
3097
原创 [算法问题]判断一个数是不是2的幂?
bool Is2Power(int nNum){ return nNum > 0 ? ((nNum & (~nNum + 1)) == nNum ? true : false) : false;}
2016-09-20 19:35:26
575
原创 349. Intersection of Two Arrays
349. Intersection of Two Arrays QuestionEditorial Solution My SubmissionsTotal Accepted: 40099Total Submissions: 89846Difficulty: EasyGiven two arrays, write a func
2016-08-24 15:05:30
280
原创 371. Sum of Two Integers(位运算)
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Credits:Special thanks to @fujiaozhu for adding this
2016-08-19 14:53:22
214
转载 水手分椰子类型题简易通解公式及推导(完整版)
转自:http://blog.sina.com.cn/s/blog_a1494e1301013w7v.html序:“水手分椰子”是趣味数学题”水手、猴子和椰子”的习惯简称,在中国被改为(五猴分桃)这是一个世界有名的趣味数学题,首先刊登在美国《星期六晚邮报》上,据说,最早是由偉大物理学家狄拉克提出来的,这一貌似简单的问题曾困扰住了他为了获得简便的計算方法,他把问题提供给当时的一些
2016-08-18 16:17:58
9279
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人