自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(57)
  • 收藏
  • 关注

原创 167. Two Sum II - Input array is sorted

给定一个有序的数组和一个目标值,在数组中寻找两个数,使得两数相加等于目标值,返回这两个数的下标。假设每个目标数只有一个解决方案,数组中每个数只能使用一次,返回的时候,前面的下标小于后面的下标例如:[2,7,11,15]  target=9;return index1=1,index2=2;class Solution {public: vector twoSum(vect

2017-11-03 16:12:39 247

原创 69. Sqrt(x)

Descrclass Solution {public: int mySqrt(int x) { if(x==0) return 0; int mid; int start=1,end=min(x/2,46340); while(start<end) { mid=(start+end)/2; if(x/mid>=mid x/(mid+1)

2017-11-03 16:05:56 307

原创 35. Search Insert Position

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would

2017-11-03 15:45:38 259

原创 125. Valid Palindrome

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For exampl

2017-11-01 21:24:15 261

原创 67. Add Binary

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".

2017-11-01 21:10:58 237

原创 58. Length of Last Word

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word

2017-11-01 21:02:23 250

原创 38. Count and Say

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113.

2017-11-01 20:51:16 269

原创 28. Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Seen this question in a real interview before?   Yes 

2017-11-01 20:21:31 195

原创 20. Valid Parentheses

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

2017-11-01 19:52:27 248

原创 14. Longest Common Prefix

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneWrite a function to find the longest common prefix string amongst an array of strings.Seen this question in

2017-11-01 19:33:55 305

原创 13. Roman to Integer

DescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.

2017-11-01 19:13:10 317

原创 88. 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) to hold addit

2017-10-10 14:49:59 225

原创 125. 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 car" is not a pa

2017-10-03 21:30:59 208

原创 141. 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?翻译:给定一个链表,确定链表是否有一个循环分析:快慢指针解题/** * Definition for singly-linked list. * s

2017-10-03 21:26:10 202

原创 167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers

2017-10-03 21:15:28 238

原创 344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".翻译:将给定字符串进行翻转,后输出翻转后的字符串。例如:hello 变成ollehclass Solution{public:

2017-10-03 21:10:06 178

原创 234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?翻译:给定一个链表,判断是否是回文。方法一:使用数组 o(n)方法二:使用栈,从左到右遍历链表,压栈。出栈判断o(n/2)方法三:使用变

2017-10-03 20:56:23 203

原创 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your

2017-10-03 20:41:52 286

原创 345. Reverse Vowels of a String

翻译: 编写一个函数,将字符串中的元音字母进行调换。输出新字符串分析:首先,确定哪些是元音。大小写的a e i o u 总共十个字母。例如:hello 其中e和o是元音,调换两者的位置。变成holleleetcode 其中元音字母有e e o e。一四进行调换,二三进行调换,结果为leotcede方法一:设置一个数组专门储存字符串中的元音字母的下标,然后两两进行调换。cla

2017-10-03 16:54:41 244

原创 350. Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as many t

2017-10-03 15:18:42 268

原创 349. Intersection of Two Arrays

Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result

2017-10-03 15:06:47 187

原创 532. K-diff Pairs in an Array

Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers

2017-10-03 14:48:52 217

原创 typedef与#define的区别

typedef,说明一种新类型名,来代替已有的类型名。格式:typedef 类型名 标识符(也就是可以用标识符代替类型名)typedef在编译时进行处理,会有类型检查。而#define是宏定义的替换 //#define用法例子: #define f(x) x*x int main() { int a=6, b=2, c;

2017-09-06 14:42:07 320

原创 蜜蜂训练2044

/*有一只经过训练的蜜蜂能爬向右侧相邻的蜂房,不能反向爬行,请编程计算蜜蜂从蜂房a爬到蜂房b的可能的路线数。*/#includeusing namespace std;long long data[52];int n,a,b;long long sum=0;int main(){    cin>>n;    data[1]=1;    data[2]

2017-05-05 15:35:29 505

原创 超级楼梯

/*有一个楼梯,共有M级,刚开始时你在第一级,若每次只能跨上一级或者两级,要走上这M级,一共有多少种走法?输入:输入包含一个整数N,表示测试的实例的组数,然后是n行数据,每行包含一个整数M,表示楼梯的级数。M的取值为1到40.*/递推求解#includeusing namespace std;long long data[42];int main(){

2017-05-05 15:16:02 215

原创 数字三角形

/*给出一个数字三角形,从三角形的顶部到底部有很多条不同的路径。对于每条路径,把路径上面的数加起来可以得到一个和,你的任务就是找到最大的和。注意:路径上的每一步只能从一个数走到下一层的它最接近的左边的那个数或者右边的那个数。                                               7                            

2017-05-05 14:53:32 608

原创 PHP中数组常用的函数汇总

1.数组的键、值函数    array_values();返回数组中所有元素的值    array_keys();返回数组中符合条件的元素的键    bool in_array(needle, haystack);检查数组中是否存在某个值    array_search(needle, haystack);进行检索,返回的是相应的键名    bool array_key_exi

2017-04-07 17:02:09 315

原创 高精度的乘法应用

/*对于一个实数R(0输入:输入包括多组R和n,R的值占第1列到第六列,n的值占第8和第9列。输出:对于每组输入,要求输出一行,该行包含精确的R的n次方,输出需要去掉前导的0后不要的0,如果输出的是整数,则不要输出小数点分析:输入比较规范,前六位是第一个数A,后面是该数的N次方,大整数的乘法可以模拟笔算乘法来做    第一步:处理输入的数A的小数点,先把小数点去掉,

2017-04-02 16:11:43 401

原创 高精度的大数的加法运算

/*输入:输入文件的第一行为一个整数,表示输入文件中接下来会有N组数据,魅族数据最多包含100行,每行由一个非常长的十进制整数组成,这个整数的长度不会超过100个    字符,而且只包含数字,每组数据的最后一行为0,表示这组数据结束。魅族数据之间会有一个空行。*/#include#include#includeusing namespace std;int main

2017-03-30 21:00:44 343

原创 初等算数

/*高精度的计算的时候,采用这种方式:用字符串读入数据,用数组存储数据Primary Arithmetic两个数相加的时候需要进位的次数输入数据有若干组,每组数据包含两个无符号的整数a,b对于每组数据,输出两个数相加需要进位的次数。按照如下输出格式。*/#include#include#includeusing namespace std;   

2017-03-29 14:34:21 310

原创 Big Number 的数组的使用

利用数组承载值,就是有可能不让你开这么大的数组#include#includeusing namespace std;const int N = 10000000;double data[N];int m,n;int main(){    data[0]=1;    data[1]=1;    for(int i=2;i        d

2017-03-29 10:45:40 442

原创 用Stirling公式的应用

/*求m!的位数,1使用Stirling公式进行求解  n!~~~~~~(n/e)^n(2*pi*n)^(1/2)*/#include#includeusing namespace std;const double e=2.7182818284590452354,pi=3.141592653589793239;double str_ling(int n)

2017-03-29 10:25:18 637

原创 C语言合法标识符

gets的用法:char a[50];gets(a);cout/*输入一个字符串,判断其是否是C的合法标识符。输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。此题的关键在于抓住命名的规则:1

2017-03-28 17:33:31 1678

原创 绝对值排序

/*输入n(n输入数据有多组,每组占一行,每行的第一个数字为n,接着是n个整数,n=0表示输入数据的结束,不做处理。对于每个测试实例,输出排序后的结果,两个数之间用一个空格隔开。每个测试实例占一行。*/#include#includeusing namespace std;int data[105];int main(){    int n;   

2017-03-27 16:06:05 398

原创 数列有序

/*有n(n输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束,本行不做处理。对于每个测试实例,输出插入新的元素后的数列。*/#includeusing namespace std;const int N=101;int data[N];int n,x,l,r,mid;int m

2017-03-27 12:44:19 326

原创 母牛的故事

/*有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0n=0表示输入数据的结束,不做处理。对于每个测试实例,输出在第n年的时候母牛的数量。每个输出占一行。*/#includeusing namespace st

2017-03-27 10:34:18 275

原创 字符串统计

对于给定的一个字符串,统计其中数字字符出现的次数。输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。对于每个测试实例,输出该串中数值的个数,每个输出占一行。*/#include#include#includeusing namespace std;int main(){    char str[100

2017-03-26 15:09:34 339

原创 数据的交换输出

/*输入n(n输入数据有多组,每组占一行,每行的开始是一个整数n,表示这个测试实例的数值的个数,跟着就是n个整数。n=0表示输入的结束,不做处理。对于每组输入数据,输出交换后的数列,每组输出占一行。*/#includeusing namespace std;int num[110];int main(){    int temp,min,n,m;  

2017-03-26 14:46:54 273

原创 偶数求和

/*有一个长度为n(n输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。对于每组输入数据,输出一个平均值序列,每组输出占一行。#includeusing namespace std;const int N=110;int d[N];int n,m;int main(){    while(cin>>n>>m)    { 

2017-03-26 13:42:32 313

原创 评委会打分

/*青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。输入数据有多组,每组占一行,每行的第一个数是n(2对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。*/#include#include#include#includeusing namespace std;con

2017-03-26 11:00:29 778

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除