c++
文章平均质量分 56
码农少年
这个作者很懒,什么都没留下…
展开
-
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pa原创 2015-12-09 15:24:19 · 157 阅读 · 0 评论 -
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 another原创 2015-12-11 14:30:53 · 141 阅读 · 0 评论 -
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 is原创 2015-12-11 14:48:47 · 174 阅读 · 0 评论 -
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 you ca原创 2015-12-10 17:30:36 · 156 阅读 · 0 评论 -
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"].class Solution {public: vector summaryRanges原创 2015-12-11 16:50:41 · 232 阅读 · 0 评论 -
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) { if(n == 0 ) return false; while(n != 1){原创 2015-12-11 17:01:30 · 174 阅读 · 0 评论 -
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 for singly-linked list.原创 2015-12-11 18:33:47 · 157 阅读 · 0 评论 -
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 o原创 2015-12-11 19:06:25 · 180 阅读 · 0 评论 -
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 sinc原创 2015-12-11 19:16:19 · 168 阅读 · 0 评论 -
Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/** * Definition for原创 2015-12-11 18:58:35 · 261 阅读 · 0 评论 -
Longest Palindromic Substring 最长回文字符串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Solu原创 2015-12-21 21:18:49 · 228 阅读 · 0 评论 -
Longest Palindromic Substring 最长回文
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Soluti原创 2015-12-21 21:27:33 · 225 阅读 · 0 评论 -
Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-12-09 15:51:24 · 173 阅读 · 0 评论 -
Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.我们知道2是最小的质数,那么2的倍数均不为质数(因为它们可以分解为一个数*2),所以我们可以将小于n的数中2的倍数,全部排除掉。排除掉2的整数倍后,剩下的数中大于2的最小的数就是下一个质数,也就是3.同样我们可以排转载 2015-12-11 13:02:29 · 389 阅读 · 0 评论 -
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 o原创 2015-12-11 11:07:56 · 188 阅读 · 0 评论 -
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-12-11 10:44:52 · 155 阅读 · 0 评论 -
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 al原创 2015-12-10 10:58:48 · 177 阅读 · 0 评论 -
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 c原创 2015-12-10 10:06:08 · 210 阅读 · 0 评论 -
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 实际上就是把10进制原创 2015-12-10 10:30:32 · 197 阅读 · 0 评论 -
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 ... Z ->原创 2015-12-10 16:36:21 · 174 阅读 · 0 评论 -
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.class原创 2015-12-11 15:11:07 · 236 阅读 · 0 评论 -
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 total ar原创 2015-12-11 15:34:48 · 210 阅读 · 0 评论 -
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原创 2015-12-11 16:01:39 · 180 阅读 · 0 评论 -
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 { * int原创 2015-12-11 16:14:50 · 185 阅读 · 0 评论 -
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-12-11 11:18:45 · 184 阅读 · 0 评论 -
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 00000000原创 2015-12-11 10:27:39 · 167 阅读 · 0 评论 -
Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating all转载 2015-12-10 17:05:45 · 146 阅读 · 0 评论 -
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 as001110010111原创 2015-12-11 10:16:38 · 155 阅读 · 0 评论 -
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-12-09 16:10:54 · 162 阅读 · 0 评论