- 博客(51)
- 资源 (6)
- 收藏
- 关注
原创 LeetCode刷题(C++)—— Pascal's Triangle(Easy)
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution {pu
2017-05-22 09:45:42 483
原创 LeetCode刷题(C++)——Same Tree(Easy)
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:递归,判断根结
2017-05-21 11:28:43 349
原创 C++中stringstream的用法
stringstream类的使用C++引入了ostringstream、istringstream、stringstream这三个类,要使用他们创建对象就必须包含sstream.h头文件。istringstream类用于执行C++风格的串流的输入操作。ostringstream类用于执行C风格的串流的输出操作。strstream类同时可以支持C风格的串流的输入输
2017-05-21 11:09:45 934
转载 解决win10 VC++6.0 应用程序无法正常运行 0xc0000142
解决win10 VC++6.0 应用程序无法正常运行 0xc0000142本文转载自:http://blog.csdn.net/w_9449/article/details/52864135,具体方法如下:下载好我分享的英文版msdev.exe(http://pan.baidu.com/s/1qYElbDq)解压出来,然后找你的vc的安装目录。如果你没有安装
2017-05-20 11:20:15 6915 1
原创 LeetCode刷题(C++)——Verify Preorder Serialization of a Binary Tree(Medium)
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.
2017-05-19 18:47:07 308
原创 LeetCode刷题(C++)——Sort List(Medium)
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) :
2017-05-19 14:57:37 371
原创 LeetCode刷题(C++)——Odd Even Linked List(Medium)
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2017-05-19 10:53:46 293
原创 LeetCode刷题(C++)——Linked List Cycle II(Medium)
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?/**
2017-05-18 20:30:11 342
原创 LeetCode刷题(C++)——Linked List Cycle(Easy)
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:设置两个指针fast和slow,fast一次走两步,slow一次走一步,如果链表有环,两指针一定相遇,并且一定是在环中相遇。否则,链表就没有环/**
2017-05-18 20:01:10 294
原创 LeetCode刷题(C++)——Remove Duplicates from Sorted Array II(Medium)
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 fi
2017-05-15 11:55:06 274
原创 LeetCode刷题(C++)——Word Search(Medium)
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically
2017-05-14 21:45:48 390
原创 LeetCode刷题(C++)——Length of Last Word(Easy)
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
2017-05-14 17:05:07 420
原创 LeetCode刷题(C++)——Rotate List(Medium)
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./** * Definition for singly-link
2017-05-14 16:54:00 337
原创 LeetCode刷题(C++)——Sort Colors(Medium)
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
2017-05-13 17:34:41 442
原创 LeetCode刷题(C++)——Search a 2D Matrix(Medium)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2017-05-13 13:12:03 350
原创 LeetCode刷题(C++)——Remove Duplicates from Sorted List II(Medium)
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-
2017-05-11 21:20:40 244
原创 LeetCode刷题(C++)——Remove Duplicates from Sorted List(Easy)
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./** * Definition for s
2017-05-11 20:14:51 296
原创 LeetCode刷题——Swap Nodes in Pairs(Medium)
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2017-05-10 15:58:01 272
原创 LeetCode刷题(C++)——Merge k Sorted Lists(Hard)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne
2017-05-10 14:39:00 321
原创 LeetCode刷题(C++)——Next Permutation(Medium)
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible
2017-05-09 20:54:01 376
原创 LeetCode刷题(C++)——Count and Say(Easy )
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2017-05-09 19:52:29 282
原创 LeetCode刷题(C++)——Search Insert Position(Easy)
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2017-05-09 11:31:47 330
原创 LeetCode刷题(C++)——4Sum(Medium)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution
2017-05-09 10:30:25 437
原创 LeetCode刷题(C++)——Edit Distance(Hard)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2017-05-08 20:10:21 658
原创 LeetCode刷题(C++)——Maximum Subarray(Easy)
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] ha
2017-05-08 18:56:09 393
原创 LeetCode刷题(C++)——Minimum Path Sum(Medium)
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2017-05-08 15:06:13 344
原创 LeetCode刷题(C++)——Divide Two Integers(Medium)
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) { if (d
2017-05-07 21:49:59 534
原创 C++中字符串匹配算法strstr()函数用法
strstr()const char* _cdecl strstr(const char* _Str, const char* _Substr);char* _cdecl strstr(char* _String, const char* _SubString);strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首
2017-05-07 16:14:28 19162 3
原创 LeetCode刷题(C++)——Implement strStr()(Easy)
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.strStr()函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现的地址;否则,返回NUL
2017-05-07 15:34:48 581
原创 LeetCode刷题(C++)——Remove Element(Easy)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.
2017-05-07 14:32:16 504
原创 LeetCode刷题(C++)——Remove Duplicates from Sorted Array(Easy)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2017-05-07 14:21:42 255
原创 LeetCode刷题(C++)——Generate Parentheses(Medium)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())
2017-05-07 09:16:02 365
原创 LeetCode刷题(C++)——Merge Two Sorted Lists(Easy)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct Lis
2017-05-06 21:30:57 276
原创 LeetCode刷题(C++)——Letter Combinations of a Phone Number(Medium)
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st
2017-05-06 20:55:24 591
原创 LeetCode刷题(C++)——Valid Parentheses(Easy)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va
2017-05-06 19:53:51 282
原创 LeetCode刷题(C++)——Remove Nth Node From End of List(Medium)
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the
2017-05-06 16:46:21 616
原创 LeetCode刷题(C++)——3Sum Closest(Medium)
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2017-05-04 20:24:40 335
原创 LeetCode刷题(C++)——3Sum(Medium)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain
2017-05-04 19:43:17 338
原创 LeetCode刷题(C++)——Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2017-05-04 10:51:12 484
原创 LeetCode刷题(C++)——ZigZag Conversion(Medium)
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
2017-05-04 08:26:01 399
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人