- 博客(44)
- 资源 (2)
- 收藏
- 关注
原创 Unique Paths
题目名称 Unique Paths—LeetCode链接描述 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 time. The r
2015-10-30 15:33:04 372
原创 学习C++,应该循序渐进看哪些书?
阶段 1《Essential C++》 这是一本内容不多但很实用的C++入门书籍,强调快速上手与理解C++编程。本书主要围绕一系列逐渐复杂的程序问题,以及用以解决这些问题的语言特性展开讲解。你不只学到C++的函数和结构,也会学习到它们的设计目的和基本原理。 《C++ Primer》 本书对C++基本概念、技术、以及现代C++编程风格进行了全面而且权威的阐述,是C++初学者的最佳指南;本书可以
2015-10-29 22:01:53 1409
原创 使用class或struct关键字定义类
1.访问控制与封装 在C++语言中,我们使用访问说明符(access specifiers)加强类的封装性。定义在public说明符之后的成员在整个程序内可被访问,public成员定义类的接口。定义在private说明符之后的成员可以被类的成员函数访问,但是不能被使用该类的代码访问,private部分封装了(即隐藏了)类的实现细节。 一个类可以包含0个或多个访问说明符,而且对于某个访问
2015-10-29 20:52:54 3068
原创 Container With Most Water
题目名称 Container With Most Water—LeetCode链接描述 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
2015-10-29 17:09:28 381
原创 Set Matrix Zeroes
题目名称 Set Matrix Zeroes—LeetCode链接描述 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.分析 给定一个m x n 的矩阵,如果一个元素为0,则将这个元素所在的行和列的元素全部设置为0. 这里有一个设置元素先后的问题:
2015-10-29 13:28:21 584
原创 Search a 2D Matrix
题目名称 Search a 2D Matrix—LeetCode链接描述 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 r
2015-10-29 12:35:01 288
原创 Spiral Matrix II
题目名称 Spiral Matrix II—LeetCode链接描述 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the following matrix:[ [
2015-10-28 22:00:34 369
原创 Rotate Image
题目名称 Rotate Image—LeetCode链接描述 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-10-28 17:27:31 358
原创 Minimum Path Sum
题目名称 Minimum Path Sum—LeetCode链接描述 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 o
2015-10-28 15:00:45 425
原创 Sort Colors
题目名称 Sort Colors—LeetCode链接描述 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
2015-10-27 16:55:22 313
原创 Gray Code
题目名称 Gray Code—LeetCode链接描述 The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the cod
2015-10-27 16:21:47 594
原创 Find Minimum in Rotated Sorted Array
题目名称 Find Minimum in Rotated Sorted Array—LeetCode链接描述 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).Find the minimum elem
2015-10-27 15:11:36 334
原创 Maximum Subarray
题目名称 Maximum Subarray—LeetCode链接描述 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 c
2015-10-27 14:34:43 379
原创 详谈C++中数组作为函数参数
一、一个例子引发的思考 运行以下代码,请问输出是什么?例子来源于《剑指Offer》,我对书上例子做了修改,让其可以运行。#include<iostream>using namespace std;int GetSize(int data[]) { return sizeof(data);}int main() { int data1[] = {1,2,3,4,5};
2015-10-26 12:33:48 16323
原创 Unique Binary Search Trees
题目名称 Unique Binary Search Trees—LeetCode链接描述 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 unique BST’s.
2015-10-26 10:01:27 298
原创 Catalan数—求解n个节点能组成的二叉树个数问题
1.catalan简介 卡塔兰数是组合数学中一个常在各种计数问题中出现的数列。以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名。历史上,清代数学家明安图(1692年-1763年)在其《割圜密率捷法》最早用到“卡塔兰数”,远远早于卡塔兰。有中国学者建议将此数命名为“明安图数”或“明安图-卡塔兰数”。卡塔兰数的一般公式为 C(n,2n)/(n+1)。2.性质 令h(0)=1,h(1)=1
2015-10-26 09:57:39 5998 1
原创 Missing Number(讲解一个非常好的方法)
题目名称 Missing Number—LeetCode链接描述 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note:
2015-10-26 09:26:04 2485
原创 Populating Next Right Pointers in Each Node
题目名称 Populating Next Right Pointers in Each Node—LeetCode链接描述 Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next poi
2015-10-24 20:03:10 256
原创 Linked List Cycle
题目名称 Linked List Cycle—LeetCode连接描述 Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?分析 检测一个单链表是否有循环,思路就是用两个指针,一个快指针,一个慢指针。慢指针每次向后移动一个节
2015-10-24 19:28:45 296
原创 Best Time to Buy and Sell Stock II
题目名称 Best Time to Buy and Sell Stock II—LeetCode链接描述 Say 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 com
2015-10-23 16:44:32 566
原创 一个代码渣渣的修炼之路——新手入门
大学就读于武汉某985高校,计算机专业,本科四年不怎么会编程,也没写过几行代码,就靠着认真复习期末考试也拿过几年奖学金,然后顺利又读了研究生,没想过能在计算机上有太大造诣,也没想过以后能靠专业知识养活自己。 之前网易游戏来武汉招聘,作为网易游戏在武大的校园大使,真真切切地体会到了想要拿到一个offer不是那么容易的事情。不管是算法能力,项目能力还是知识积累,我都在一个很低的水平,也就是从那之后
2015-10-22 17:12:27 820 1
原创 House Robber
题目名称 House Robber—LeetCode链接描述 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 eac
2015-10-22 16:36:00 364
原创 Valid Sudoku
题目名称 Submission Details—LeetCode链接描述 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the charact
2015-10-22 11:59:13 428
原创 Min Stack
题目名称 Submission Details—LeetCode链接描述 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 ele
2015-10-21 11:26:33 297
原创 C++中数据类型转换
1.stringstream简介 C++引入了ostringstream、istringstream、stringstream这三个类,要使用他们创建对象就必须包含sstream.h头文件。 (1)istringstream类用于执行C++风格的串流的输入操作。 (2)ostringstream类用于执行C风格的串流的输出操作。 (3)strstream类同时可以支持C风格的串流的输入输
2015-10-20 19:13:22 790
原创 Compare Version Numbers
题目名称 Compare Version Numbers—LeetCode链接描述 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that
2015-10-20 18:19:05 320
原创 Summary Ranges
题目名称 Summary Ranges—LeetCode链接描述 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"].分析 这道题题目意思很明确,对一个给定的
2015-10-20 16:00:06 416
原创 First Bad Version
题目名称 First Bad Version—LeetCode链接描述 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since e
2015-10-20 13:26:42 314
原创 Excel Sheet Column Title
题目名称 Excel Sheet Column Title—LeetCode链接描述 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
2015-10-19 18:52:31 318
原创 Rotate Array
题目名称 Rotate Array—LeetCode链接描述 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 a
2015-10-19 17:47:52 312
原创 ZigZag Conversion
题目名称 ZigZag Conversion—LeetCode链接描述 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 le
2015-10-18 19:50:27 301
原创 Valid Palindrome
题目名称 Valid Palindrome—LeetCode链接描述 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 pal
2015-10-18 12:22:21 241
原创 Reverse Bits
题目名称 Reverse Bits—LeetCode链接描述 Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (repres
2015-10-17 17:07:26 357
原创 Merge Sorted Array
题目名称 Merge Sorted Array—LeetCode链接描述 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greate
2015-10-16 17:33:51 423
原创 Word Pattern
题目名称 Word Pattern—LeetCode链接描述 Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a
2015-10-16 16:13:07 437
原创 Isomorphic Strings
题目名称 Isomorphic Strings—LeetCode链接描述 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 charac
2015-10-15 21:34:41 606
转载 大公司笔试面试有哪些经典算法题目?
首先,强烈建议采用“题海战术”。我当然不会告诉题主,今年面了数十家公司,90%的题目是原题(没办法,就那几个知识点,能有什么新题) 题库在哪里呢?按照循序渐进的原则,一一介绍:cc150,全名cracking the coding interview - 150 Programming Questions and Solutions。经典中的经典,曾有人别的啥都不做,刷这本书三四遍,拿了Goog
2015-10-15 18:44:14 2638
原创 Palindrome Number
题目名称 Palindrome Number—LeetCode链接描述 Determine whether an integer is a palindrome. Do this without extra space.分析 判断一个数是否为回文数。回文数 我才用的方法是将整数转换成字符串,利用上一篇文章中讲到的C++字符串流<sstream>。设定一前一后指针,分别指向字符串的头尾,如果不
2015-10-15 10:20:13 530
原创 C++中将string按照空白字符分割的新方法
使用stringstream对象简化类型转换 首先要引入头文件<sstream>,C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性、类型安全和可扩展性。 <sstream>库是最近才被列入C++标准的。(不要把<sstream>与标准发布前被删掉的<strstream>弄混了。)因此,老一点的编译器,如GCC2.95,并不支持它。如果你
2015-10-14 13:25:03 42025 3
原创 Remove Linked List Elements
题目名称 Remove Linked List Elements—LetCode链接描述 Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –>
2015-10-14 11:04:19 446
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人