- 博客(14)
- 收藏
- 关注
原创 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 9 to 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. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 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
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人