- 博客(66)
- 资源 (3)
- 收藏
- 关注
原创 3. 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
2016-03-29 23:41:51 249
原创 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-03-29 14:52:40 168
原创 326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?题意:判断一个数(int 型)是否是3的幂。思路:用int型最大的3的幂的那个数,即3*3*3*3......
2016-03-28 22:14:47 202
原创 303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan
2016-03-28 21:34:28 167
原创 299. Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2016-03-27 11:03:48 210
原创 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the
2016-03-26 18:48:13 191
原创 290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
2016-03-25 17:20:56 210
原创 283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you
2016-03-25 15:52:25 169
原创 278. First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2016-03-25 15:34:59 231
原创 263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly si
2016-03-25 11:34:51 172
原创 258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2016-03-25 11:14:53 154
原创 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass
2016-03-25 00:13:11 158
原创 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 val
2016-03-24 23:34:33 184
原创 235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw
2016-03-24 23:15:06 188
原创 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 fo
2016-03-24 21:58:51 175
原创 232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(
2016-03-23 17:01:41 132
原创 231. Power of Two
Given an integer, write a function to determine if it is a power of two.题意:判断一个数是否为2的幂。思路:2的幂的二进制表示里只有一个1,所以通过检测n的二进制表示里1的个数即可。注意:输入的n可能为负数。class Solution {public: bool isPowerOfTwo(int n) {
2016-03-23 16:00:09 196
原创 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"].题意:输出有序数组的连续的序列。思路:直接输出。stringstream的使用。class S
2016-03-23 15:25:48 148
原创 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1题意:把一个树对称翻转。思路:其实是把一棵树的左右子树调换。递归实现即可。参照了101. Symmetric Tree 代码如下:
2016-03-23 12:55:21 160
原创 225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2016-03-23 11:20:22 202
原创 223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2016-03-23 10:56:16 170
原创 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.题
2016-03-23 09:41:52 170
原创 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2016-03-23 08:43:01 157
原创 206. Reverse Linked List
Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?题意:对链表进行逆序。思路1:迭代逆序。/** * Definiti
2016-03-22 23:49:10 206
原创 205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2016-03-22 21:47:03 147
原创 204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases.Hint:Let's
2016-03-22 21:07:48 256
原创 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题意:删除链表中指定值的结点。思路:遍历
2016-03-22 19:52:16 174
原创 202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2016-03-22 16:45:08 165
原创 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2016-03-22 16:02:21 210
原创 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000
2016-03-22 10:53:08 201
原创 190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101
2016-03-22 09:49:58 176
原创 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
2016-03-21 23:59:45 201
原创 172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.题意:求n的阶乘结果里会有多少个0思路:这个问题跟5有关,找跟5有关的个数。class Solution {publi
2016-03-21 23:35:05 189
原创 229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint:How many majority elements could i
2016-03-21 22:06:45 187
原创 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element
2016-03-21 14:32:12 202
原创 171. Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...
2016-03-21 14:23:24 179
原创 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 题意:26个英文字
2016-03-21 08:39:50 195
原创 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2016-03-21 00:17:58 267
原创 cuda环境安装--windows离线安装
1.下载离线安装包。NVIDIA的官网为www.nvidia.com,进入communities->developer zone->cuda zone->cuda toolkit 下载对应版本。2.双击,同意协议,下一步等,完成。3.进入C:\ProgramData\NVIDIA Corporation\CUDA Samples\v7.5,找到5_Simulations/nbody,用对应
2016-03-20 21:33:52 1808
原创 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-03-20 17:05:29 241
CUDA编程指南
2016-04-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人