- 博客(20)
- 资源 (18)
- 收藏
- 关注
原创 【leetcode】3Sum, 3Sum Closest
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c
2016-06-03 20:42:31
393
原创 【leetcode】Implement strStr()
曾经被百度面试官虐的时候碰到过这题。注意:字符串以'\0'结束,NULL和'\0'不等价。暴力解决:外循环:遍历haystack;内循环:遍历needle,若字符不匹配则跳出,当遍历到needle结束时,返回当前i,若遍历到haystack结束,则不存在匹配子串,返回-1。int strStr(char* haystack, char* needle){ if
2016-06-03 15:00:08
353
原创 【leetcode】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.思路:将链表尾部和头部连起来,顺便算出链表长度len计算k
2016-06-02 21:36:50
390
原创 【leetcode】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 answer is "
2016-06-02 21:29:45
375
原创 【leetcode】Minimum Window Substring
class Solution {public: string minWindow(string s, string t) { vector dict(128, 0); for (auto c : t) ++dict[c]; int counter = t.size(); int begin =
2016-06-02 13:49:47
483
原创 【leetcode】Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number
2016-05-31 11:53:12
359
原创 【C++】非递归求二叉树的前序和中序序列
Keyword:stack前序:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right
2015-11-23 22:08:19
555
原创 【leetcode】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
2015-11-19 21:39:03
342
原创 【leetcode】Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2015-11-19 21:17:01
341
原创 【leetcode】Best Time to Buy and Sell Stock II
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 complete as many transactions as you like (ie, buy on
2015-11-19 20:35:43
427
原创 【leetcode】Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given
2015-11-19 20:01:49
412
原创 【OpenCL】初学摘要(一)
因项目需要,开始真正学习OpenCL了,以下是我所阅读过的所有资料的一个个人的摘要整理,近期持续更新。方便以后自己回顾以及其他同学参考。资料来源:OpenCL编程指南,AMD OpenCL大学课程ppt,OpenCL贴吧。并行任务并行:把一个问题分解为能够同时执行的多个任务。数据并行:同一个任务内,它的各个部分同时执行。多核cpu适合基于任务的并行编程,GPU更适应于数据并行编
2015-03-15 20:54:09
2711
原创 【C++】Primer 9.39
#include #include #include #include //EXIT_SUCCESS, FAILUREusing namespace std;int main(){ string line1 = "We were her pride of 10 she named us:"; string line2 = "Benjamin, Phoneix, the Pr
2014-09-15 22:12:49
674
原创 the C programming language 练习
p13 ,练习1-9#include void main(){ int c = getchar(); int lastc = 0; while (c != '\n') { if ((c!=' ') || (lastc!=' ')) //输出字符的条件集合 putchar(c); lastc = c; c = getchar(); } putchar('\n'
2014-05-18 21:39:16
872
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人