- 博客(55)
- 资源 (1)
- 收藏
- 关注
原创 Leetcode——459. Repeated Substring Pattern
问题Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engl
2017-01-30 19:20:56 484
原创 Leetcode——287. Find the Duplicate Number
题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, f
2017-01-27 15:56:53 332
原创 Leetcode——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 elemen
2017-01-26 22:59:43 276
原创 Leetcode——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 th
2017-01-26 19:25:20 267
原创 Leetcode——75. Sort Colors
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,
2017-01-26 14:38:54 339
原创 Leetcode——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.解答One Solution:/** * Definition for sin
2017-01-26 00:55:41 319
原创 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?原题: https://
2017-01-26 00:13:41 304
原创 Leetcode——264. Ugly Number II
题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ug
2017-01-24 18:20:52 443
原创 Leetcode——313. Super Ugly Number
题目Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16
2017-01-24 00:58:37 332
原创 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:F(k) = 0 * B
2017-01-23 18:23:04 314
原创 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 < 231).Example 1:Input:3Outp
2017-01-23 17:24:06 269
原创 Leetcode——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, string b) { int i=0;
2017-01-23 00:12:10 260
原创 Leetcode——231. Power of Two
回答Given an integer, write a function to determine if it is a power of two.解答class Solution {public: bool isPowerOfTwo(int n) { int MaxPowerOfTwo=pow(2,(int)(log10(INT_MAX)/log10(2)));
2017-01-22 21:02:07 261
原创 Leetcode——171. Excel Sheet Column Number
题目https://leetcode.com/problems/excel-sheet-column-number/解答其实就是26进制转化为十进制class Solution {public: int titleToNumber(string s) { int res=0; for(int i=0;i<s.length();i++) {
2017-01-21 23:48:40 220
原创 Leetcode——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?解答Method1:循环或者递归public boolean isPowerOfThree(int n) { r
2017-01-21 20:27:38 215
原创 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]Output:3
2017-01-21 16:04:49 255
转载 欢迎使用CSDN-markdown编辑器
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl
2017-01-21 15:17:12 234
原创 Leetcode——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 only one digit,
2017-01-18 00:00:22 242
原创 Leetcode——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.解析class Solution {//0来自于5*2,因为2的个数总是大于等于5,所以有多少个零就看有多少个5public: int tr
2017-01-17 23:20:39 308
原创 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 3,
2017-01-16 21:10:04 252
原创 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?解答找到链表的一半,把剩下的进行反转,然后比对前后一半。 找到链表的一半:fast和slow两个指针,fast每次递增2,slow每次递增1,也可以用count。
2017-01-16 14:10:36 229
原创 Leetcode——206. Reverse Linked List
题目Reverse a singly linked list.解答反转链表!循环class Solution1 {public: ListNode* reverseList(ListNode* head) { if(head==NULL) return NULL; ListNode *p=head; ListNode *pn=p->next,
2017-01-15 16:53:25 231
原创 Leetcode——203. Remove Linked List Elements
题目Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5解答典型的在链表头部多申请一个指针指向链表头部,解决问题!/** * Defin
2017-01-15 16:04:46 252
原创 Leetcode——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.解答链表的运用! Easy!/** * Definiti
2017-01-15 15:54:46 308
原创 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 ↘
2017-01-15 15:34:11 234
原创 Leetcode——409. Longest Palindrome
题目Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is not consid
2017-01-14 23:04:31 219
原创 Leetcode——438. Find All Anagrams in a String
题目Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be larger
2017-01-14 22:33:22 204
原创 Leetcode——447. Number of Boomerangs
最近写文章总想用英语来写,但是自己的英语又poor,写的又慢,没办法,只能中英mixed着吧!我真不是装B,我是真的想practice My English!ProblemGiven n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that
2017-01-13 22:20:05 311
原创 Leetcode——202. Happy Number
QuestionWrite 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 squa
2017-01-13 16:47:31 326
原创 Leetcode——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 start with a isPr
2017-01-13 11:26:16 346
原创 Leetcode——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 assume the
2017-01-12 14:54:46 213
原创 Leetcode——463. Island Perimeter
题目You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely
2017-01-12 14:05:38 315
原创 Leetcode——389. Find the Difference
题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added i
2017-01-12 11:44:25 232
原创 Leetcode——136. Single Number
题目Given an array of integers, every element appears twice except for one. Find that single one.解答使用异或运算,XOR!!! 大杀器!!!class Solution {//using xorpublic: int singleNumber(vector<int>& nums) {
2017-01-12 11:16:22 203
原创 Leetcode——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 th
2017-01-12 10:55:04 232
原创 Leetcode——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.Examples:
2017-01-11 21:58:01 404
原创 isstringstream——WOW!Amazing!
背景在做Leetcode的第290题时,看到Discuss里有一个简答的方法,只需要十几行代码,里面有一个C++的输入输出控制类isstringstream,简直是太牛逼了!大大简化代码!!!#介绍,转自 (http://blog.sina.com.cn/s/blog_a9303fd90101adt6.html) 一个比较有用的c++的输入输出控制类。C++引入了ostringstream、is
2017-01-11 20:58:19 1908 1
原创 Leetcode——350. Intersection of Two Arrays II
题目Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note: Each element in the result should appear as many times as i
2017-01-11 17:17:57 348
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人