- 博客(25)
- 收藏
- 关注
原创 [leetcode]217. Contains Duplicate
Given 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 should return false if every element
2017-03-29 20:57:51 197
原创 [leetcode]206. Reverse Linked List
Reverse a singly linked list. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class
2017-03-29 20:17:33 185
原创 [leetcode]205. Isomorphic Strings
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 character must be replaced with anot
2017-03-29 17:41:57 275
转载 STL 算法 <algorithm>中各种算法解析
转载地址:http://blog.csdn.net/tianshuai1111/article/details/7674327 一,巡防算法 for_each(容器起始地址,容器结束地址,要执行的方法) [html] view plain copy #include iostream> #includ
2017-03-29 17:13:13 1832
转载 C++:STL标准入门汇总
第一部分:(参考百度百科) 一、STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称。它是由Alexander Stepanov、Meng Lee和David R Musser在惠普实验室工作时所开发出来 的。现在虽说它主要出现在C++中,但在被引入C++之前该技术就已经存在了很长的一段时间。
2017-03-29 17:10:38 214
转载 [leetcode]204. Count Primes
Description: Count the number of prime numbers less than a non-negative number, n. 返回质数的个数 解题思路: ①设置一个bool型的数组,最开始都初始化为true ②从2到n-1,假设i*i ③统计2到n-1中存在多少个true class Solution { publi
2017-03-29 17:01:55 200
转载 C# SSH XML
SSH: Granados是一个基于.NET的SSH客户端库。它有以下特点: 1.Granados是一个C#的开源项目。源码地址:http://www.routrek.co.jp/support/download/varaterm/granados200.tar.gz 2.同时支持SSH1和SSH2。 3.Granados实现了AES, Blowfish, TripleDES, R
2017-03-27 11:12:54 589
原创 [leetcode]16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2017-03-22 16:21:27 203
转载 [leetcode]15. 3Sum
这个问题参考别人的代码,现在给出解决思路: ①首先对输入矩阵进行排序,变成从小到大或者从大到小的形式(在这里采用从小到大的形式) ②由于找到三个数的和为0,运用三个索引表示这三个数,i,j,k ③i表示第一个数,在这里对i进行[0,size-1]的循环 j=i+1表示大于i的第一个数,k=size-1,表示最大的数 分别计算i+j+k对应数值,将结果保存在total变量中,之后
2017-03-22 15:58:44 179
原创 461. Hamming Distance
class Solution { public: int hammingDistance(int x, int y) { int z; z = x ^ y; int num = 0; for(int i=0; i<32; i++) { int tmp = 1<<i;
2017-03-16 13:31:05 159
原创 [leetcode]202. Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2017-03-14 09:44:25 202
原创 [leetcode]191. Number of 1 Bits
这个题在昨晚190后开始写,一次成功,果然位操作还是王道 class Solution { public: int hammingWeight(uint32_t n) { int result = 0; for(int i=0; i<32; i++) { int tmp = n & 0x01;
2017-03-13 22:04:21 190
转载 [leetcode]190. Reverse Bits
这个题参考的是网上的思路 class Solution { public: uint32_t reverseBits(uint32_t n) { int result = 0; for(int i=0; i<32; i++) { int tmp = n & 0x01; n = n>>1;
2017-03-13 21:56:13 257
原创 [leetcode]189. Rotate Array
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]. class Solution { public: void rotat
2017-03-06 09:39:16 157
转载 [leetcode]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 nu
2017-03-05 16:03:08 182
原创 [leetcode]125. Valid Palindrome
我的思路:将有效的字符存起来(不包含符号和空格),之后判断是否为回文序列 class Solution { public: bool isPalindrome(string s) { if(s.size()<2) return true; vector input; for(int i=0; i<s.size();
2017-03-04 10:38:37 202
转载 [leetcode]122. Best Time to Buy and Sell Stock II
想复杂了,参考了别人的思路class Solution { public: int maxProfit(vector& prices) { int total = 0; for(int i=1; i<prices.size(); i++) { if((prices[i]-prices[i-1])>0)
2017-03-03 16:59:40 307
原创 [leetcode]67. Add Binary
思路1:将a和b先转换成int,转换成10进制,进行相加,结果转换成2进制,结果转换成char类型 放弃原因:题目上并没写a和b的大小和范围,int型有最大上限,可能会溢出 思路2:读取a,b当前位,转换成int进行进位和当前位的判断 放弃原因:转换成Int的过程中和思路3相比不是一个最优解,需要一次char-int和一次int-char的过程 思路3:当char强制转化成Int是对其as
2017-03-03 16:33:34 226
原创 [leetcode]88. Merge Sorted Array
思路1:直接将num1和num2进行比较,在num1中插入num2的值。本来想按照这个思路下去,结果总是出错,于是换了一种思路。 思路2:将复制num1,按照归并排序的方式进行排序 相比来说思路1更省空间,是可行的,更优 class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n
2017-03-03 16:25:58 277
原创 [leetcode]121. Best Time to Buy and Sell Stock
思路:有一个值记录前面最小值,有一个值记录最大值。这个题本来想多了,一看是easy类型的,就往简单想,果然是easy类型的 class Solution { public: int maxProfit(vector& prices) { if(prices.size()<2) return 0; int min =
2017-03-03 16:20:32 214
原创 [leetcode]53. Maximum Subarray
参考了一个算法,链接如下: http://blog.csdn.net/joylnwang/article/details/6859677 然而算法只看懂了第一部分,最大字串假设是[i,j]那么i class Solution { public: int maxSubArray(vector& nums) { int length = nums.size();
2017-03-02 14:21:16 166
原创 [leetcode]66. Plus One
通过数组存放着一个正数,对它进行加1操作。这个题需要考虑进位,但是如果当前进位为0,那么之后也不会出现溢出的问题,比如说1189,加1后就是1190,进行计算时,计算到十位8+1(进位),如果十位小于10,那么百位和千位都不用进行处理了,这样能够节约时间。 class Solution { public: vector plusOne(vector& digits) {
2017-03-02 10:22:45 187
原创 [leetcode]38. Count and Say
题目描述:其实刚看到题目没看懂是什么意思,后来看懂了。 输入n=1 默认1 输入n=2 前面的数据是一个1,记作11 输入n=3 前面的数据是两个1,记作21 输入n=4 前面的数据是一个2一个1,记作1211 输入n=5 前面的数据时一个1一个2两个1,记作111221 …… 前面的数据如果连着就练着数,如11就是连着记作21,相邻字母不同如
2017-03-02 09:50:23 166
原创 [leetcode]28. Implement strStr()
实现strStr(),返回needle在haystack中第一次出现的索引号,如果没有找到输出-1 第一次pass 73/74,根据提醒,如果haystack="a" needle=" " 默认空和任何数都是匹配的。 我写的时间复杂度有些大,是O(n2) class Solution { public: int strStr(string haystack, string nee
2017-03-01 11:33:17 170
原创 [leetcode]9. Palindrome Number
判断一个整数是不是回文结构(aba abccba) 这个代码居然一!次!过!!!容我开心一会 我的思路是将int型转换成char型,之后计算char的长度,进行翻转,比如abcd编程dcba,将翻转后的对应字符和翻转前对比,如果一致不操作,不一致返回false。 class Solution { public: bool isPalindrome(int x) { c
2017-03-01 10:26:45 162
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人