- 博客(50)
- 资源 (4)
- 收藏
- 关注
原创 各种排序算法汇总
1.冒泡排序冒泡排序,如其名,该算法如同气泡上上升一样, 每次循环比较把最小的数交换到最前面,循环次数为n-1,时间复杂度为O(n^2)void swap(vectorint>& arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;}//冒泡排序void bubble
2017-04-21 12:26:28 331
转载 Python机器学习库
来源转自:http://www.open-open.com/lib/view/open1404282093842.htmlPython在科学计算领域,有两个重要的扩展模块:Numpy和Scipy。 其中Numpy是一个用python实现的科学计算包。包括:一个强大的N维数组对象Array;比较成熟的(广播)函数库;用于整合C/C++和Fortran代码的工具包;
2017-04-20 10:19:26 664
原创 leetcodeOJ 557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"
2017-04-14 09:21:08 369
原创 leetcodeOJ 80. Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five e
2017-04-13 22:28:01 235
原创 leetcodeOJ 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 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1
2017-04-13 21:52:26 209
原创 leetcodeOJ 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition for s
2017-04-13 21:33:19 205
原创 leetcodeOJ 71. 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 yo
2017-04-13 18:31:11 241
原创 leetcodeOJ 63. Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid
2017-04-13 17:05:17 209
原创 leetcodeOJ 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 in this array.Could you do it without extr
2017-04-13 16:47:59 228
原创 leetcodeOJ 520. Detect Capital
Given 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 holds:All letters in thi
2017-04-13 16:43:05 260
原创 leetcodeOJ 52. N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.方法类似leetcodeOJ51题class Solution {public: int totalNQueens(int n)
2017-04-13 10:40:24 244
原创 leetcodeOJ 51. 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.E
2017-04-13 10:34:21 266
原创 leetcodeOJ 216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Input:
2017-04-13 09:46:12 227
原创 leetcodeOJ 77. 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],]
2017-04-13 09:22:03 231
原创 leetcodeOJ 189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo
2017-04-12 17:08:01 249
原创 leetcodeOJ 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-link
2017-04-12 15:59:12 215
原创 leetcodeOJ 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
2017-04-12 15:25:48 230
原创 leetcodeOJ 162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in
2017-04-12 15:24:46 199
原创 leetcodeOJ 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may as
2017-04-10 12:03:56 197
原创 leetcodeOJ 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:
2017-04-10 11:07:19 241
原创 leetcodeOJ 90. 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
2017-04-09 23:06:01 201
原创 leetcodeOJ 78. Subsets
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],
2017-04-09 22:44:21 215
原创 leetcodeOJ 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[ [2], [3,4], [
2017-04-09 21:59:32 182
原创 leetcodeOJ 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?思路跟leetcodeO
2017-04-09 21:21:18 170
原创 leetcodeOJ 118. Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]代码如下://打印杨辉三角class Soluti
2017-04-09 21:17:40 270
原创 leetcodeOJ 22. 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:[ "((()))", "(()())", "(())()", "()(())",
2017-04-09 17:30:41 280
原创 leetcodeOJ 228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].题意:把数组中连续数字a,a+1, a+2, ..., b表示成"a->b"代码如下:class
2017-04-09 16:26:57 226
原创 leetcodeOJ 62. 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 bo
2017-04-09 15:56:42 165
原创 leetcodeOJ 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2017-04-09 15:29:26 185
原创 leetcodeOJ 16. 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
2017-04-09 11:00:26 197
原创 leetcodeOJ 43. Multiply Strings
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0
2017-04-09 10:13:14 256
原创 leetcodeOJ 537. 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"Outpu
2017-04-09 09:38:04 209
原创 leetcodeOJ 66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits a
2017-04-07 15:59:25 390
原创 leetcodeOJ 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".位操作,从右向左加,注意进位,得到的字符串最后需要逆转class Solution {public: string addBinary(string a,
2017-04-07 15:27:34 284
原创 leetcodeOJ 121. 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), d
2017-04-07 15:06:16 153
原创 leetcodeOJ 53. 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,1] has
2017-04-07 14:40:15 234
原创 leetcodeOJ 91. Decode Ways
参考了大牛的博客:http://blog.csdn.net/linhuanmars/article/details/24570759A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26
2017-04-07 12:12:05 273
原创 leetcodeOJ 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive
2017-04-07 11:01:49 190
原创 leetcodeOJ 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:可以两两进行归并排序,代码如下:/** * Definition for singly-linked list. * struct ListNode { * int
2017-04-07 10:06:33 227
原创 leetcodeOJ 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity. 在O(nlogn)时间内,给一单向链表排序 分析,时间复杂度有要求,考虑用mergesort 取单向链表的中间元素:ListNode* temp = head;//temp每次移动一步 ListNode* pre = he
2017-04-07 09:44:46 203
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人