- 博客(38)
- 资源 (3)
- 收藏
- 关注
原创 86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2016-06-30 16:49:04 156
原创 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-
2016-06-30 16:09:06 257
原创 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.题意:给出一个链表和一个数k,然后将链表的后k个结点反转到首部。思
2016-06-30 15:20:30 132
原创 187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2016-06-29 17:12:57 173
原创 166. Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2016-06-29 16:32:48 178
原创 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-06-29 14:31:19 133
原创 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题意:根据一个排序后的数组,构造一颗平衡的二叉搜索树。思路:中间的结点为根,然后构建左子树,然后构建右子树;再然后又是建树问题,递归解决之。/** * Definition for a bin
2016-06-29 13:41:15 156
原创 49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: Al
2016-06-29 13:36:11 148
原创 43. Multiply Strings
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-06-29 11:05:25 153
原创 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho
2016-06-28 11:39:39 141
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.题意:根据中序序列和后序序列,构建出一颗二叉树。思路:先找根,再找左树的范围,再找右树的范围,分别构建左
2016-06-28 11:32:56 185
原创 289. Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m
2016-06-28 11:27:10 294
原创 73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m
2016-06-27 22:56:16 458
原创 59. Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2016-06-27 22:28:39 155
原创 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2016-06-27 22:17:05 156
原创 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?题意:把一个n*n的矩阵,顺时针旋转90度。思路:开辟一个新的二维数组,计算二维下标的对应关系,然
2016-06-27 21:20:55 145
原创 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-06-27 20:12:05 221
原创 134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to
2016-06-27 17:59:06 180
原创 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-06-27 17:05:51 230
原创 275. H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is sorted.题
2016-06-27 16:38:33 173
原创 274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A
2016-06-27 16:22:58 245
原创 227. Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should
2016-06-27 15:39:12 169
原创 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the
2016-06-26 17:26:54 177
原创 222. Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille
2016-06-25 22:12:28 188
原创 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2016-06-25 21:17:33 145
原创 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, i
2016-06-23 17:12:22 149
原创 154. Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk
2016-06-23 15:57:41 186
原创 153. Find Minimum 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).Find the minimum element.You may assume no duplicate exists in
2016-06-23 15:24:03 177
原创 74. 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
2016-06-20 16:03:47 156
原创 PPT设计要领
网上看了一些PPT设计的一些简单要领,现总结一下:1. 留白就是要在内容的四周进行留白,尤其是下部要进行留白。视觉需要。在默认的基础上,缩小字号,增大行距。在默认的基础上,缩小字号,加大段距。注意:如果有视觉障碍物,则留白的空白是内容的边界距离障碍物边界的之间的距离。总结:适当的距离产生美。2. 丢掉默认,选择适当面对默认字体默认的宋体字:适合较小的字体,用于大段的正文。但用于标题或者
2016-06-20 13:58:24 674
原创 CUDA的一些总结和体会
导论GPU怎么产生的,以及后续发生了哪些变化?实时、高清晰度的三维图形需要大量的计算,单纯的CPU无法满足这种需求。由于这种需求的推动,图形处理器(GPU)就逐渐演化成高并行度,多线程,拥有强大的计算能力和极高的存储器带宽的多核处理器。GPU和CPU的浮点计算能力差异的原因是:GPU是特别为计算密集,高并行度计算(如图像渲染)设计的,因此GPU将更多的晶体管用于数据计算而不是数据缓存和流程控制
2016-06-20 13:30:16 8142
原创 69. Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.题意:计算x的平方根。思路:在0,n之间查找这个平方根,二分查找,满足i^2x, 则返回i即可。class Solution {public: int mySqrt(int x) { if (x < 2) return x
2016-06-15 21:58:33 2891
原创 50. Pow(x, n)
Implement pow(x, n).题意:实现pow(x, n)思路:二分;设pow(x, n/2)=q, 则pow(x, n)= n%2==0? q*q : q*q*x。n是负数是,pow(x,n)= pow(1/x, -n)。class Solution {public: double myPow(double x, int n) { if (x == 0 || x =
2016-06-15 21:18:32 451
原创 排序和顺序统计量
很多计算机科学家认为排序是算法研究中最基础的问题,不仅如此,有的学者指出对待解决问题先进行排序,可能有利于的问题的分析以及求解思路的产生。排序算法1 插入排序2 归并排序3 堆排序31 堆311 维护堆的性质312 建堆32 堆排序算法33 优先队列4 快速排序5 计数排序6 基数排序和桶排序7 总结和要求顺序统计量1 最小值和最大值2 期望为线性时间的选择算法3 最
2016-06-12 23:08:58 2922
原创 计数排序
在已知待排序的元素范围为0-k之间时,可使用计数排序。当k=O(n)时,此时运行时间为Θ(n)。思路是:记录对应元素出现的次数,则可以推算出改元素在排序后中的数组的下标。void counting_sort(vector<int>& A, vector<int>& B, int k){ vector<int> C(k + 1, 0); for (int i = 0; i < A.si
2016-06-12 12:29:56 309
原创 35. 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.
2016-06-12 10:03:19 157
原创 归并排序
归并排序,复杂度O(nlgn)。 思路是每次将数组分成两部分,然后对各部分进行排序,通过合并(归并)操作将两段已经排序过的数组进行整合,形成新的排序数组的顺序。void merge(vector<int>& nums, int left, int mid, int right){ vector<int> L(nums.begin() + left, nums.begin() + mid+1
2016-06-12 09:53:56 188
原创 29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题意:实现两个数相除,不能使用乘,除,和取余运算。思路:先都取绝对值,然后除数左移接近被除数,累加此时左移的个数,直至被除数小于除数时停止。clas
2016-06-08 15:51:08 188
CUDA编程指南
2016-04-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人