c++
woquhundan
这个作者很懒,什么都没留下…
展开
-
由string删除某个字符的操作发现的一个问题
最近在看C++primer,3.2 标准库类型string有一个习题,写一个程序将输入的字符串中的符号删除后输出。我新建了一个字符串接收非符号的字符串,但是最后输出结尾部分总是多一个a。#include#include#includeusing namespace std;int main(){ string dd,dd2; cin >> dd; decltype(dd.size()原创 2015-05-17 21:52:16 · 1223 阅读 · 0 评论 -
LeetCode:Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe原创 2015-08-29 22:14:54 · 218 阅读 · 0 评论 -
LeetCode: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(v原创 2015-08-29 20:07:57 · 213 阅读 · 0 评论 -
LeetCode: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(原创 2015-08-28 15:26:34 · 255 阅读 · 0 评论 -
LeetCode: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){ return 0; } while原创 2015-08-28 17:10:39 · 224 阅读 · 0 评论 -
LeetCode: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?要求时间复杂度为n,想了一下只能用快慢两个指针做,先找到中点,然后倒置后面一半链表比较。写的过程中放了好多低级错误,基础还是要加强啊。class S原创 2015-08-27 22:12:53 · 256 阅读 · 0 评论 -
LeetCode: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 a原创 2015-08-26 20:30:00 · 262 阅读 · 0 评论 -
LeetCode: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"]class Sol原创 2015-08-26 16:00:49 · 267 阅读 · 0 评论 -
LeetCode: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原创 2015-08-26 12:50:19 · 319 阅读 · 0 评论 -
LeetCode: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原创 2015-08-24 21:28:26 · 315 阅读 · 0 评论 -
LeetCode:Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2015-08-24 17:13:43 · 236 阅读 · 0 评论 -
LeetCode: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 ...原创 2015-08-24 15:45:54 · 242 阅读 · 0 评论 -
c++实现快速排序
两种方法实现c++原创 2015-05-01 15:29:22 · 268 阅读 · 0 评论 -
LeetCode:ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2015-08-30 18:17:05 · 240 阅读 · 0 评论