leetcode
文章平均质量分 72
guicaisa
这个作者很懒,什么都没留下…
展开
-
leetcode刷题。记录,总结,备忘。217
leetcode刷题217Contains DuplicateGiven 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 shou原创 2015-06-16 23:05:32 · 296 阅读 · 0 评论 -
leetcode 刷题, 总结,记录,备忘 35
leetcode刷题35Search Insert Position 最近刷题还比较有感觉,,难道是我水平在提高?。。其实是做到了比较简单的题目。。。Given a sorted array and a target value, return the index if the target is found. If not, return the index wh原创 2015-06-17 23:14:01 · 263 阅读 · 0 评论 -
leetcode刷题。总结,记录,备忘。168
leetcode168题。先进行取模计算,得到最后一个位的字符,然后再进行求商运算,获得前面位的字符值,从右向左添加至结果字符串中。考虑到52应该是AZ,所以必须减去1,再进行求商运算,才能得到第一位是Aclass Solution {public: string convertToTitle(int n) { string result; char ch;原创 2015-05-30 00:03:58 · 384 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘 226
leetcode226题。invert Binary Tree倒置二叉树。想不到这题还有个梗,挺有意思的。我一开始自作聪明,想用一个栈一个队列来做,用中序遍历,把节点push进栈中,把节点的指push进队列中,遍历完之后,分别从栈顶和队列顶拿出节点和数值,赋值。一开始想着感觉还挺对的,,递交了几次都没过,后来我发现加入最右的子叶节点为空,,,那赋值就全错位了。。应该是在一个满二叉树的情况才适用原创 2015-06-18 23:55:50 · 370 阅读 · 0 评论 -
leetcode刷题, 总结,记录,备忘 171
leetcode题目171Related 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原创 2015-05-30 22:26:27 · 338 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘 169
leetcode169Majority ElementGiven 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 no原创 2015-06-21 23:47:53 · 291 阅读 · 0 评论 -
leetcode刷题 ,总结,记录,备忘。144
leetcode144题。Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note:原创 2015-06-02 21:14:11 · 325 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘137
leetcode137Single Number II Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime comp原创 2015-06-23 00:08:46 · 335 阅读 · 0 评论 -
leetcode刷题,总结,记录,备注 94
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2015-06-03 22:20:47 · 436 阅读 · 0 评论 -
leetcode刷题,总结,笔记,备忘。136
从通过率最高的题目开始136 Single Number找出数组里唯一一个只出现一次的数字。通过这个题目知道位异或运算符连续异或2个相同的数字得到0。/*Given an array of integers, every element appears twice except for one. Find that single one. *Note: *Your algorithm原创 2015-05-22 22:33:58 · 479 阅读 · 2 评论 -
leetcode刷题 总结,记录,备注 53
leetcode刷题53Maximum Subarray 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原创 2015-06-25 22:55:32 · 355 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘83
leetcode83.Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Giv原创 2015-06-24 22:45:24 · 268 阅读 · 0 评论 -
leetcode刷题。总结,记录,备忘 100
leetcode 100题是判断2个二叉树是否相同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原创 2015-05-23 22:13:06 · 389 阅读 · 0 评论 -
leetcode刷题。总结,记录,备忘 104
leetcode104题,计算二叉树的深度。Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.第一种方法采用递归,以遍历到原创 2015-05-23 21:45:53 · 382 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘70
leetcode70Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2015-06-26 22:30:31 · 329 阅读 · 0 评论 -
leetcode 刷题目,总结,记录,备忘 13
leetcode13Roman to IntegerGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.这个题目,,不说了,,,去百度罗马数字的一些规则,,,比如C在D或者M前面是-100的意思。上代码。。。原创 2015-06-27 23:01:15 · 295 阅读 · 0 评论 -
leetcode刷题,总结,记录, 备忘 141
leetcode141题。Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode {原创 2015-06-07 22:37:03 · 387 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘 108
leetcode108Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.这个题目使用递归和二分即可,一直寻找数组的中点,作为根节点,将数组截为两半,分别递归原创 2015-06-28 22:27:26 · 393 阅读 · 0 评论 -
leetcode刷题,总结, 记录,备忘 12
leetcode12Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999之前那个题的姊妹篇,首先强调!没什么难的,,,把罗马数字的规则搞搞清楚就行了,,,我写的代码写的太多了,,,全原创 2015-06-29 22:35:49 · 258 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘。116
leetcode116题Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its原创 2015-06-09 13:20:29 · 711 阅读 · 0 评论 -
leetcode刷题。总结,记录,备忘 191
leetcode191题,求一个32无符号整数中位为1的个数,2种方法,最简单的就是使用c++中bitset容器,直接使用count()这个成员函数即可class Solution {public: int hammingWeight(uint32_t n) { bitset bu(n); return bu.count();原创 2015-05-24 21:30:17 · 380 阅读 · 0 评论 -
leetcode刷题, 总结,记录,备忘 232
leetcode232Implement 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原创 2015-07-07 20:45:29 · 323 阅读 · 0 评论 -
leetcode 总结,记录,备忘。153
leetcode153。。。Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Fi原创 2015-06-30 21:36:08 · 390 阅读 · 0 评论 -
leetcode刷题, 总结,记录,备忘145
leetcode145Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2原创 2015-07-09 15:27:07 · 787 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘 75
leetcode75Sort Colors 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原创 2015-07-08 22:32:47 · 341 阅读 · 0 评论 -
leetcode刷题 总结 记录, 备忘 62
leetcode62Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in原创 2015-07-02 22:24:51 · 393 阅读 · 0 评论 -
leetcode刷题 ,总结,记录,备忘27
leetcode27Remove Element Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter wha原创 2015-07-12 21:09:57 · 281 阅读 · 0 评论 -
leetcode刷题。总结,记录,备忘 122
leetcode刷题154Best Time to Buy and Sell Stock IISay 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原创 2015-07-26 14:43:22 · 392 阅读 · 0 评论 -
leetcode刷题,总结,记录 ,备忘48
leetcode48Rotate Image You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?这个题目,直接用列作为外层循环,原创 2015-07-11 21:18:38 · 371 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘。96
leetcode刷题96Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 uni原创 2015-06-15 22:57:19 · 426 阅读 · 0 评论 -
leetcode刷题, 总结 记录 , 备忘21
leetcode21Merge Two Sorted Lists 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.不是很难的一个题目,原创 2015-07-05 23:08:00 · 357 阅读 · 0 评论 -
leetcode刷题, 总结 ,记录 ,备忘 121
leetcode121Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one t原创 2015-07-06 23:09:33 · 342 阅读 · 0 评论 -
leetcode刷题 总结 记录 备忘 64
leetcode64Minimum Path Sum 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:原创 2015-07-27 18:28:47 · 696 阅读 · 0 评论 -
leetcode刷题, 总结,记录,备忘 110
leetcode110Balanced 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原创 2015-07-13 22:19:52 · 285 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘24
leetcode24Swap Nodes in Pairs 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原创 2015-07-07 20:38:13 · 348 阅读 · 0 评论 -
leetcode刷题, 总结,记录,备忘22
leetcdoe22Generate Parentheses 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:原创 2015-07-07 20:41:30 · 314 阅读 · 0 评论 -
leetcode刷题目 ,总结,记录,备忘206
leetcode206Reverse Linked List Reverse a singly linked list这个类型的题目我之前做过一次,那次我是用递归写的,但是这次我用递归写却超时了,,具体方法就是一头栽进链表最下面,然后返回,将每一层节点一个一个钩在后面即可。由于超时我就老老实实的使用了栈来使用,还是比较简单,入栈再弹栈,不多说了。原创 2015-07-14 19:01:20 · 313 阅读 · 0 评论 -
leetcode刷题 总结 记录 备忘 46
leetcode46Permutations Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,原创 2015-07-28 18:15:06 · 307 阅读 · 0 评论 -
leetcode刷题,总结,记录,备忘238
leetcode238Product of Array Except Self Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums原创 2015-07-16 19:41:54 · 447 阅读 · 0 评论 -
leetcode刷题目 总结 记录 备忘11
leetcode11Container 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 e原创 2015-07-29 22:15:12 · 321 阅读 · 0 评论