- 博客(209)
- 收藏
- 关注
原创 C++ 概念
If you define a class like this:class X: public Y{ private: int m_a; char* m_b; Z m_c;};The following methods will be defined by your compiler.Const
2015-03-24 14:03:55 677
原创 杂记
1. 静态链表第一个元素value为任意值, next为12.Copy&Assignment constructor 3法: default,在public里实现,在private里实现(不是所有的都能实现)3. Multidimensional Vectorvectorint> > vec(4, vectorint>(4));4.原码,反码,补码 正数:原反补
2012-02-01 13:15:37 608
原创 Segment Tree and Binary index tree
Segment Tree:http://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/http://www.geeksforgeeks.org/segment-tree-set-1-range-minimum-query/Binary Indexed Tree:http://www.geeks
2016-06-23 10:46:14 1148
原创 LeetCode: Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lett
2015-06-25 09:58:23 507
原创 LeetCode: Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: // Initialize your data s
2015-06-24 14:13:28 699
原创 LeetCode: 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
2015-06-21 05:15:31 797
原创 LeetCode: Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * struct TreeNode { *
2015-06-21 01:58:44 772
原创 LeetCode: Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at most
2015-06-19 12:09:54 580
原创 LeetCode: 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
2015-06-04 03:26:52 436
原创 LeetCode: 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
2015-06-04 03:04:54 404
原创 LeetCode: 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
2015-06-04 01:51:26 427
原创 LeetCode: 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
2015-06-03 14:19:51 474
原创 LeetCode: 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
2015-06-03 13:59:15 460
原创 LeetCode: Count Primes
Count the number of prime numbers less than a non-negative number, n.class Solution {public: int countPrimes(int n) { bool isPrime[n]; int result = 0; memset(isPrime, 1,
2015-06-03 13:47:49 390
原创 LeetCode: 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
2015-06-03 12:38:36 412
原创 LeetCode: Reverse Linked Lis
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?Iterative:/** * Definition for singl
2015-06-03 12:12:45 501
原创 LeetCode: 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
2015-06-03 11:21:40 468
原创 LeetCode: Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p
2015-05-18 11:56:00 323
原创 LeetCode: Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2015-05-06 23:42:56 434
原创 LeetCode: Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may no
2015-05-05 04:46:03 399
原创 LeetCode:
Scramble String Total Accepted: 25901 Total Submissions: 108031My SubmissionsQuestion Solution Given a string s1, we may represent it as a binary tree by partitioning it to two n
2015-04-16 05:42:42 456
原创 C++ Exception
Exception type:Derived types (scattered throughout different library headers)bad_allocException thrown on failure allocating memory (class )bad_castException thrown on failure to dyn
2015-03-29 01:34:36 1004
原创 LeetCode: Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i
2015-03-23 12:33:59 449
原创 LeetCode: 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.
2015-03-17 23:20:43 406
原创 LeetCode: Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found
2015-03-14 15:27:39 323
原创 LeetCode: Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2015-03-11 14:47:00 512
原创 LeetCode: 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
2015-03-10 14:10:38 466
原创 LeetCode: 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
2015-03-09 13:43:21 382
原创 LeetCode: Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()
2015-03-07 10:46:24 375
原创 LeetCode: Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2015-03-04 15:44:30 421
原创 LeetCode: 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 {public: int trailingZeroes(int n) { int
2015-03-04 14:26:53 373
原创 LeetCode: 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 ↘
2015-03-03 01:01:55 344
原创 LeetCode: 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
2015-03-02 15:33:26 469
原创 LeetCode: 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 class Sol
2015-03-02 13:00:54 375
原创 LeetCode: 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
2015-03-02 12:25:20 441
原创 LeetCode: Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class
2015-03-02 10:17:17 418
原创 LeetCode: 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
2015-03-02 10:17:09 367
原创 LeetCode: Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n))class Solution {public: doubl
2015-03-01 16:16:32 658 1
原创 LeetCode: 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
2015-02-27 01:12:33 363
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人