[leetcode]242. Valid Anagram

给两个string类型的变量s和t,判断s和t是否是相同字母异序词 例如:s = "anagram", t = "nagaram", return true. s = "rat", t = "car", r...

2017-06-28 09:52:31

阅读数:80

评论数:0

[leetcode]160. Intersection of Two Linked Lists

思路参考博客:http://blog.csdn.net/nomasp/article/details/50572819 代码如下: /** * Definition for singly-linked list. * struct ListNode { * int val; *...

2017-06-27 11:35:33

阅读数:130

评论数:0

[leetcode] Add to List 169. Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume th...

2017-06-26 15:55:34

阅读数:188

评论数:0

[leetcode]168. Excel Sheet Column Title

我的思路: 相当于是26进制,不过需要考虑一下没有0的情况,写一个函数不断的返回传入参数除以26后的结果,要特别考虑当传入数据余数为0的情况,此时应该将余数作为26进行处理 代码如下,一次过 class Solution { public: string convertToT...

2017-06-26 15:33:31

阅读数:161

评论数:0

[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 ...

2017-03-29 20:57:51

阅读数:91

评论数:0

[leetcode]206. Reverse Linked List

Reverse a singly linked list. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListN...

2017-03-29 20:17:33

阅读数:74

评论数:0

[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 oc...

2017-03-29 17:41:57

阅读数:123

评论数:0

[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到...

2017-03-29 17:01:55

阅读数:68

评论数:0

[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...

2017-03-22 16:21:27

阅读数:100

评论数:0

[leetcode]15. 3Sum

这个问题参考别人的代码,现在给出解决思路: ①首先对输入矩阵进行排序,变成从小到大或者从大到小的形式(在这里采用从小到大的形式) ②由于找到三个数的和为0,运用三个索引表示这三个数,i,j,k ③i表示第一个数,在这里对i进行[0,size-1]的循环    j=i+1表示大于i的第一个数,k=s...

2017-03-22 15:58:44

阅读数:78

评论数:0

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;...

2017-03-16 13:31:05

阅读数:76

评论数:0

[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 p...

2017-03-14 09:44:25

阅读数:78

评论数:0

[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+...

2017-03-13 22:04:21

阅读数:77

评论数:0

[leetcode]190. Reverse Bits

这个题参考的是网上的思路 class Solution { public: uint32_t reverseBits(uint32_t n) { int result = 0; for(int i=0; i<32; i++) { ...

2017-03-13 21:56:13

阅读数:126

评论数:0

[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...

2017-03-06 09:39:16

阅读数:66

评论数:0

[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 ...

2017-03-05 16:03:08

阅读数:66

评论数:0

[leetcode]125. Valid Palindrome

我的思路:将有效的字符存起来(不包含符号和空格),之后判断是否为回文序列 class Solution { public: bool isPalindrome(string s) { if(s.size()<2) return true; ...

2017-03-04 10:38:37

阅读数:78

评论数:0

[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++) ...

2017-03-03 16:59:40

阅读数:178

评论数:0

[leetcode]67. Add Binary

思路1:将a和b先转换成int,转换成10进制,进行相加,结果转换成2进制,结果转换成char类型 放弃原因:题目上并没写a和b的大小和范围,int型有最大上限,可能会溢出 思路2:读取a,b当前位,转换成int进行进位和当前位的判断 放弃原因:转换成Int的过程中和思路3相比不是一个最优解...

2017-03-03 16:33:34

阅读数:99

评论数:0

[leetcode]88. Merge Sorted Array

思路1:直接将num1和num2进行比较,在num1中插入num2的值。本来想按照这个思路下去,结果总是出错,于是换了一种思路。 思路2:将复制num1,按照归并排序的方式进行排序 相比来说思路1更省空间,是可行的,更优 class Solution { public: vo...

2017-03-03 16:25:58

阅读数:142

评论数:0

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