- 博客(53)
- 资源 (9)
- 收藏
- 关注
原创 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 (
2016-07-31 19:50:11 233
原创 Search Insert Position
一、问题描述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 th
2016-07-31 19:14:06 267
原创 进程间的通信方式
进程间通信方式有八种:1. 管道Pipe2. 命名管道FIFO3. 内存映射Memory Mapping4. 消息队列Message Queue5. 共享存储Shared Memory6. 信号量Semaphore7. 套接字Socket8. 信号Signal简单介绍如下:1. 管道pipe管道,又称为匿名管道,是一种半双工的通信方式,数据只
2016-07-23 14:31:07 376
原创 解决hash冲突的方法
虽然我们不希望发生冲突,但实际上发生冲突的可能性仍是存在的。当关键字值域远大于哈希表的长度,而且事先并不知道关键字的具体取值时。冲突就难免会发 生。另外,当关键字的实际取值大于哈希表的长度时,而且表中已装满了记录,如果插入一个新记录,不仅发生冲突,而且还会发生溢出。因此,处理冲突和溢出是 哈希技术中的两个重要问题。1、开放定址法 用开放定址法解决冲突的做法是:当冲突发生时,使用
2016-07-23 13:45:31 990
转载 C++STL之所有算法介绍
转载自:http://www.cppblog.com/y05zh/archive/2007/05/22/24644.aspx STL算法部分主要由头文件,,组成。要使用 STL中的算法函数必须包含头文件,对于数值算法须包含,中则定义了一些模板类,用来声明函数对象。 STL中算法大致分为四类: 1、非可变序列算法:指不直接修改其所操作的容器内容的算法。
2016-07-21 20:01:17 1184
原创 Multiply Strings
一、问题描述Given two numbers represented as strings, return multiplication of the numbers as a string.Note:The numbers can be arbitrarily large and are non-negative.Converting the input str
2016-07-21 18:41:40 367
原创 Longest Substring Without Repeating Characters
一、问题描述Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the
2016-07-21 17:00:23 314
原创 atoi函数实现
一、atoi函数功能将字符串变为整数,考虑正负数和空格、tab字符。二、代码int implement_atoi(const char *p){ assert(p!=NULL); int res =0; bool negflag = false; while(*p==' ' || *p == '\t') p++; if('+' == *p || '-' == *p)
2016-07-21 16:33:43 460
原创 Coin Change
一、问题描述You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amou
2016-07-20 13:54:44 297
原创 Path Sum II
一、问题描述Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5
2016-07-19 19:20:10 180
原创 Integer Break
一、问题描述二、思路根据(N/2)*(N/2)>=N, then N>=4(N-1)/2 *(N+1)/2>=N, then N>=5这两个表达式意味着因子应该小于4,最好是3,其次是2.例如:6 : 3*3 > 2*2*2三、代码class Solution {public: int integerBreak(int n) { if(
2016-07-19 17:15:33 206
原创 jason接口解析监控--Python实例
本例从配置文件中读取监控接口#!/usr/bin/python#-*- coding: UTF-8 -*-# wirte by luotianhui 2016.6.21import typesimport urllib2import jsonimport ConfigParserimport string, os, sysclass urlData: name = "
2016-07-19 16:43:09 1448
原创 C++输入
一、C++中的输入方法1、cin:当碰到空格或换行符'\n'时,输入结束:char a[10],b[10];coutcin>>a>>b;cout输出结果为:Enter some input:12 34 561234END 2、cin.getline:当碰到换行符'\n'或达到所能接受的最大字符数时,输入结束:char a[10];
2016-07-19 16:38:35 971
原创 Super Pow
一、问题描述Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8
2016-07-19 16:18:17 247
原创 hihocoder:Give My Text Back
一、题目时间限制:10000ms单点时限:1000ms内存限制:256MB描述To prepare for the English exam Little Ho collected many digital reading materials. Unfortunately the materials are messed up by a malw
2016-07-19 12:42:27 418
原创 Path Sum
一、问题描述Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary t
2016-07-17 22:31:52 244
原创 Minimum Depth of Binary Tree
一、问题描述Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.二、思路类似于Maximum Depth o
2016-07-17 17:52:20 207
原创 Integer to English Words
一、问题描述Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve
2016-07-17 17:41:54 215
原创 Integer to Roman
一、问题描述Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.二、思路分别建两个数组,一个存放边界值,另一个存储罗马字符,如果满足条件,将数字减去相应的边界值,字符串加入相应的罗马字符。三、代码clas
2016-07-17 16:19:29 244
原创 Single Number III
一、问题描述二、思路类似题目求一组数组中只出现一次的数:Single Number,本题中沿用了这个思路,但是结果result中包含两个数,这时我们取这两个数不同的一位,可以将这两个数拆分开来。令lastBit = result & -result,lastBit的含义为result从低位到高位,第一个非0位所对应的数字。三、代码class Solution {public:
2016-07-17 15:04:24 237
原创 Pow(x, n)
一、问题描述二、思路版本一利用二分法,利用奇偶性求解。公式:n为偶数:result = x ^N/2 * x^N/2;n为奇数:result = x ^N/2 * x^N/2 * x;版本二采用位运算。三、代码版本一:class Solution {public: double myPow(double x, int n) { if(x
2016-07-17 10:55:40 253
原创 Super Ugly Number
一、问题描述Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2,
2016-07-17 01:05:50 227
原创 Ugly Number II
一、问题描述Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence o
2016-07-16 21:43:44 233
原创 Balanced 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 of the two subtrees of every node
2016-07-16 17:57:07 181
原创 Plus One
一、问题描述Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.二、思路题意即为
2016-07-16 13:58:40 146
原创 Rotate List
一、问题描述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.二、思路常规思路:找到翻转后链表的尾部,然
2016-07-16 13:10:12 221
原创 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.Given 1->1->2->3->3, return 1->2->3.二、思路常规思路,即发
2016-07-16 11:35:06 154
原创 Add Binary
一、问题描述Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".二、思路开始首相想到的是暴力求解,比如先转化为十进制,然后相加,用long long类型存储,防止溢出,运行后提示超时;又想到另一种暴力
2016-07-16 10:29:08 177
原创 Count and Say
一、问题描述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
2016-07-16 00:27:25 200
原创 Merge Sorted Array
一、问题描述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 greater or equal to m + n) t
2016-07-15 23:29:45 204
原创 Linked List Cycle II
一、问题描述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.二、思路判断单链表是否有环,并且找到入口请见我另一篇博客:判断单链表是否存在环以及求出环的入口
2016-07-15 19:23:32 163
原创 Linked List Cycle
一、问题描述Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Subscribe to see which companies asked this question二、思路快慢指针
2016-07-15 18:01:02 183
原创 Intersection of Two Linked Lists
一、问题描述Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2016-07-15 00:15:31 194
原创 Binary Tree Level Order Traversal II
一、问题描述Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20
2016-07-14 21:13:08 208
原创 Valid Palindrome
一、问题描述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 palindrome."race a ca
2016-07-14 20:36:51 199
原创 Binary Tree Level Order Traversal
一、问题描述Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3
2016-07-14 19:23:37 218
原创 PHP基础知识学习笔记
一、PHP 超级全局变量超级全局变量在PHP 4.1.0之后被启用, 是PHP系统中自带的变量,在一个脚本的全部作用域中都可用。PHP 超级全局变量PHP中预定义了几个超级全局变量(superglobals) ,这意味着它们在一个脚本的全部作用域中都可用。 你不需要特别说明,就可以在函数及类中使用。PHP 超级全局变量列表: - $GLOBALS
2016-07-14 17:44:02 1946
原创 Same Tree
一、问题描述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.
2016-07-14 17:36:03 207
原创 Climbing Stairs
一、问题描述You 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?二、思路首先想到是用递归,但是递
2016-07-14 17:19:16 207
原创 Power of Three
一、问题描述二、思路方法一是数学公式;方法二1162261467 is 3 ^19,这个方法只有一行代码啊啊,可惜不实用,一般人谁会想到啊。。。三、代码方法一:class Solution {public: bool isPowerOfThree(int n) { if(n <= 0) return false; int max_p
2016-07-14 14:42:22 235
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人