- 博客(47)
- 收藏
- 关注
原创 547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is adirect friend of B, and B is a direct friend of C, then
2017-05-06 22:00:17
450
原创 542. 01 Matrix
Given 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:0 0 00 1 00
2017-03-28 21:54:23
364
原创 编程之美--2.4 1的数目之扩展问题
思路与书中2.4的类似,只是把十进制换成了二进制,只需在iFactor*10的地方,改成iFactor*2即可。代码如下:#include #includeusing namespace std;const unsigned SYSTEM = 2;unsigned long Sum1s(unsigned long n){ unsigned long iCount = 0;
2017-03-04 21:19:16
366
原创 编程之美--2.3寻找发帖“水王”之扩展问题
思路与书中2.3节寻找发帖水王的思路类似。每次删除四个不同的ID,那么在剩下的ID中,3个发帖很多的ID,发帖数目仍然超过了剩余帖子总数的1/4。可以不断重复这个过程,直至ID的不同个数等于3。代码如下:#include #include using namespace std;unsigned NumTango = 3;vector Find(const vector &
2017-03-04 20:12:20
987
转载 GBDT--梯度提升决策树
转载至:http://blog.youkuaiyun.com/w28971023/article/details/8240756GBDT--梯度提升决策树
2017-02-24 09:08:13
541
转载 推荐算法--协同滤波
转载至:http://blog.youkuaiyun.com/zy825316/article/details/18625583推荐算法--协同滤波
2017-02-24 08:55:20
1976
原创 Caffe+CUDA7.5+Ubuntu14.04配置
特别说明:本文使用2017年1月5日下载的caffe-master版本,运行平台为:Ubuntu 14.04,CUDA7.5,cuDNN v5.0,Matlab 2014b在此特别感谢一下阳博士以及欧新宇老师。一、 CUDA1. 安装CUDA ToolkitCUDA官方网址:https://developer.nvidia.com/cuda-75-downloads-archive 下载对应的版本...
2017-01-05 20:58:06
903
原创 LeetCode 477. Total Hamming Distance
The 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 between all pairs of the giv
2017-01-01 16:49:17
501
原创 LeetCode 453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou
2016-12-30 13:25:33
252
原创 LeetCode 445. Add Two Numbers II
You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a link
2016-12-30 13:24:59
282
原创 LeetCode 441. Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.
2016-12-30 13:23:35
234
原创 LeetCode 423. Reconstruct Original Digits from English
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.Note:Input contains only lowercase English letters.Input is g
2016-12-30 13:19:52
296
原创 LeetCode 415. Add Strings
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.B
2016-12-30 13:18:52
289
原创 LeetCode 413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc
2016-12-30 13:17:54
258
原创 LeetCode 400. Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive and will fit within the range of a 32-bit signed integer (n 31).Example 1:Input
2016-12-30 13:16:39
401
原创 LeetCode 397. Integer Replacement
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o
2016-12-30 13:15:04
344
原创 LeetCode 396. Rotate Function
Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:
2016-12-30 13:14:17
272
原创 LeetCode 372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example
2016-12-30 13:13:19
319
原创 LeetCode 368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solution
2016-12-30 13:12:45
236
原创 LeetCode 367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return
2016-12-30 13:11:37
243
原创 LeetCode 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-12-30 13:06:04
261
原创 LeetCode 25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2016-12-30 13:04:14
229
原创 LeetCode 24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2016-12-30 13:02:57
200
原创 LeetCode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2016-12-30 13:01:24
237
原创 LeetCode 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * struct ListNode { * int va
2016-12-30 12:55:19
225
原创 LeetCode 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 val; * ListNode *ne
2016-12-30 12:49:51
249
原创 LeetCode 21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct Lis
2016-12-30 12:48:56
207
原创 LeetCode 206. Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solu
2016-12-30 12:48:22
272
原创 LeetCode 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si
2016-12-30 12:46:49
222
原创 LeetCode 2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2016-12-30 12:45:47
228
原创 LeetCode 19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the
2016-12-30 12:45:12
201
原创 LeetCode 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2016-12-30 12:44:23
199
原创 LeetCode 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) :
2016-12-30 12:43:08
190
原创 LeetCode 147. Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
2016-12-30 12:42:17
219
原创 LeetCode 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t
2016-12-30 12:40:32
391
原创 LeetCode 137. 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 u
2016-12-30 12:39:14
238
原创 LeetCode 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?/*
2016-12-30 12:38:21
214
原创 LeetCode 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 implement it without using e
2016-12-30 12:32:38
226
原创 LeetCode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode { * int val; *
2016-12-30 11:21:19
234
原创 LeetCode 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this question/** * Definition for singly-
2016-12-30 11:20:15
234
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人