
LeetCode
文章平均质量分 76
PAUL_shuo
这个作者很懒,什么都没留下…
展开
-
LeetCode:Longest Consecutive Sequence
Problem:Longest Consecutive Sequence Total Accepted: 3391 Total Submissions: 13151My SubmissionsGiven an unsorted array of integers, find the length of the longest consecutive elem原创 2013-12-16 01:15:32 · 569 阅读 · 0 评论 -
leetcode:Plus One
Given a number represented as an array of digits, plus one to the number.分析:高精度加法的最简单形式class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution bel原创 2014-01-26 01:54:06 · 645 阅读 · 0 评论 -
leetcode:Rotate 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?分析: 其实是对于每一个格子而言,其实与其余三个格子形成循环对调原创 2014-01-26 01:48:02 · 538 阅读 · 0 评论 -
leetcode:Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2014-01-26 01:43:36 · 557 阅读 · 0 评论 -
leetcode:Permutation Sequence
Permutation Sequence Total Accepted: 3357 Total Submissions: 16092 My SubmissionsThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations原创 2014-01-26 01:42:21 · 615 阅读 · 0 评论 -
leetcode:Next Permutation
解题代码:class Solution {public: void nextPermutation(vector &num) { if (num.size()<=1) { return; } int k=num.size()-1;bool flag=false; while(k>0) { if (num[k]>num[k-1]) {原创 2014-01-26 01:32:46 · 631 阅读 · 0 评论 -
leetcode:Valid Sudoku
Valid Sudoku Total Accepted: 3495 Total Submissions: 13104My SubmissionsDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially fil原创 2014-01-26 01:57:04 · 630 阅读 · 0 评论 -
C++中的map操作
今天由于leetcode中一道题要用到c++中的hash_map,查阅了一些关于hash_map的简单使用方法,其实它跟c++中的map很像;归纳来说,在查找操作时,hash_map更快,而在增加和删除元素时map更快;关于map的用法,简单记录如下,hash_map可类比着使用map的功能:自动建立Key - value的对应。key 和 value可以是任意你需要的类型。根据key原创 2013-12-15 21:58:54 · 645 阅读 · 0 评论 -
LeetCode:Median of Two Sorted Arrays
Median of Two Sorted Arrays:分析这是一道非常经典的题。这题更通用的形式是,给定两个已经排序好的数组,找到两者所有元素中第k 大的元素。O(m + n) 的解法比较直观,直接merge 两个数组,然后求第k 大的元素。不过我们仅仅需要第k 大的元素,是不需要“排序”这么复杂的操作的。可以用一个计数器,记录当前已经找到第m 大的元素了。同时我们使用两原创 2013-12-14 15:55:58 · 594 阅读 · 0 评论 -
leetcode:Set Matrix Zeroes
Set Matrix Zeroes Total Accepted: 4726 Total Submissions: 15732My SubmissionsGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show原创 2014-01-27 19:23:59 · 764 阅读 · 0 评论