- 博客(60)
- 收藏
- 关注
原创 Leetcode Repeated DNA Sequences
class Solution {private: unordered_map hash; unordered_map revert; string retrieve(int ans){ string ret = ""; for(int i = 0; i < 10; i++){ ret += revert[(ans >
2015-02-06 15:25:01 819
原创 leetcode Reverse Words in a String II
class Solution {private: void reverseString(string &s,int i,int j){ while(i<j){ char tmp = s[i]; s[i] = s[j]; s[j] = tmp; i++;
2015-02-05 14:36:57 534
转载 Java: instanceOf vs getClass
The reason that I favor the instanceof approach is that when you use the getClassapproach, you have the restriction that objects are only equal to other objects of the same class, the same run tim
2015-01-26 23:49:48 405
转载 Why Enum Singleton are better in Java
Why Enum Singleton are better in JavaEnum Singletons are new way to implement Singleton pattern in Java by using Enum with just one instance. Though Singleton pattern in Java exists from l
2015-01-25 10:38:04 463
转载 Java Enum Tutorial: 10 Examples of Enum in Java
Java Enum Tutorial: 10 Examples of Enum in JavaWhat is Enum in Java Enum in Java is a keyword, a feature which is used to represent fixed number of well known values in Java, For example
2015-01-25 10:12:46 537
转载 Linkedin工程师是如何优化他们的Java代码的
最近在刷各大公司的技术博客的时候,我在Linkedin的技术博客上面发现了一篇很不错博文。这篇博文介绍了Linkedin信息流中间层Feed Mixer,它为Linkedin的Web主页,大学主页,公司主页以及客户端等多个分发渠道提供支撑(如下图所示)。在Feed Mixer里面用到了一个叫做SPR(念“super”)的库。博文讲的就是如何优化SPR的java代码。下面就是他们总结
2015-01-25 07:34:18 394
原创 Leetcode Largest Number
class Solution {private: bool cmp(int a,int b){ stringstream ssa, ssb; string sa,sb; ssa << a << b; ssa >> sa; ssb << b << a;
2015-01-14 08:11:04 329
转载 2015互联网校招总结—一路走来
转载请注明出处:http://blog.csdn.net/ns_code/article/details/40408397 写在前面 结束了在百度的实习,是时候写下校招的总结了,再不写估计很多东西都忘了。在开源社区混迹久了,从别人的学习、求职、工作经历中越发感受到很多的正能量,也本着攒RP的原则,向学弟学妹们,尤其非名校的学弟学妹们传递点正能量,因为博主也是非名校出身
2015-01-10 10:53:43 786
翻译 GeeksForGeeks C++与Java之间virtual关键字的不同之处
How does default virtual behavior differ in C++ and Java ?Default virtual behavior of methods is opposite in C++ and Java:In C++, class member methods are non-virtual by default. They can
2015-01-09 02:46:35 668
翻译 GeekForGeeks 何时在c++中使用初始化列表
When do we use Initializer List in C++?Initializer List is used to initialize data members of a class. The list of members to be initialized is indicated with constructor as a comma separate
2015-01-09 02:28:23 608
翻译 GeeksForGeeks java和c++的继承区别
Comparison of Inheritance in C++ and JavaThe purpose of inheritance is same in C++ and Java. Inheritance is used in both languages for reusing code and/or creating is-a relationship. There a
2015-01-09 01:53:31 398
转载 推荐!国外程序员整理的Java资源大全
http://www.importnew.com/14429.html构建这里搜集了用来构建应用程序的工具。Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建。Maven优于Apache Ant。后者采用了一种过程化的方式进行配置,所以维护起来相当困难。Gradle:Gradle采用增量构建。Gradle通过Gr
2015-01-08 13:59:32 450
原创 Leetcode Dungeon Game(经典动态规划)
class Solution {public: int calculateMinimumHP(vector > &dungeon) { int n = dungeon.size(); if(n <= 0){ return 0; } int m = dungeon[0].size();
2015-01-07 11:33:36 605
原创 判断整数乘法是否overflow
bool isOverflow(int a,int b){ //assume a and b is positive number if((a|b) > SQRT_INT_MAX && b && a > INT_MAX/b){ return true; }else{ return false; }}
2015-01-02 09:16:13 783
原创 Leetcode Binary Search Tree Iterator
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class BSTIte
2015-01-02 09:04:55 350
原创 Leetcode Factorial Trailing Zeroes
class Solution {public: int trailingZeroes(int n) { if(n<=4){ return 0; } int currAns, ans = 0; do{ ans += currAns = n / 5; n /
2015-01-01 15:27:37 449
原创 LeetCode Two Sum III - Data structure design
class TwoSum {private: unordered_map buffer;public: void add(int number) { buffer[number]++; } bool find(int value) { for(auto elem : buffer){ int num1 = elem.second;
2014-12-26 14:05:25 984
原创 Javascript自学积累(将不时更新)
var canFly = function(){ return true; }; window.isDeadly = function(){ return true; }; assert( isNimble() && canFly() && isDeadly(), "Still works, even though isNimble is moved." ); function isNimb
2014-12-24 12:33:14 484
转载 想学程式设计,你怎么能错过这 31 个学 Coding 的网站
以下为大家介绍的这 31 个线上学习 Coding 的资源,有专门给儿童、初学者、想成为 App 开发者、前端工程师、后端工程师、资料科学家、UX 设计师的 …… 只要你有毅力,好好定下心来运用这些资源来学习,几个月内成为开发者、设计师完全不是难事!不信?那就亲自去体验看看吧。1. MIT Open Courses WareMIT 拥有大量工程和资工相关的课程,它提供了所有的
2014-12-24 08:19:08 1100
原创 Leetcode的Pow(x, n) 与 sqrt(x)
Pow(x,n):class Solution {public: double pow(double x, int n) { if(x == 0){ cout<<"NaN"<<endl; return -1; } if(n == 0){ return 1;
2014-12-24 04:21:15 323
转载 关于前端学习和笔试面试的总结
前沿 以前总是希望在技术论坛和博客能有人关注,最近收到一些小伙伴请教问题的来信和私信,在深感荣幸的同时也深知自己技术和经验的不足,怕会误人子弟,所以现在打算以应届生的身份尽自己的一点绵薄之力给大家一点建议,其实也谈不上建议,只是个人的一些观点和做法,谢谢大家的关注和支持~ 关于前端学习一、多看书CSS方面:CSS权威指南,CSS禅意花园,CSS设计
2014-12-23 14:37:54 615
原创 Leetcode Permutations II 最简单的解法
class Solution {private: bool nextPermutation(vector &num){ int index, size = num.size(), swapIndex; for(index = size - 2; index >= 0 && num[index] >= num[index + 1]; index--);
2014-12-23 14:33:32 320
原创 Leetcode Climbing Stairs logN 做法
class _2by2{private: int d00,d01,d10,d11;public: _2by2(int d00,int d01,int d10,int d11):d00(d00),d01(d01),d10(d10),d11(d11){} void operator *= (const _2by2& rhs){ int td00
2014-12-23 14:24:54 549
原创 Leetcode Merge k Sorted Lists 利用stl heap来实现
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */struct Greater { bool operator() (ListN
2014-12-23 09:04:52 374
原创 概率和随机数经典面试问题:拒绝采样,蓄水池抽样,洗牌问题和随机01问题
已知rand7()[1..7],求产生rand10()[1..10]基本思路大家都知道的,就是call rand7()两次然后进行拒绝采样,因此大部分人第一下想到的算法如下:int rand10() { int row, col, idx; do { row = rand7(); col = rand7(); idx = col + (row-1)*7;
2014-12-22 03:42:50 788
原创 Leetcode Median of Two Sorted Arrays
这是一道比较难的题目,因为正常考虑的话,想在面试中解出这道题,你必须知道在两个有序数组中找第K大数的程序,然后利用那程序来解出这道题,详细如下:这里要注意的是两个有序数组中找第K大数程序中K是从1开始的,不是从0开始的。class Solution {private: int findKth(int A[], int m, int B[], int n, int k){
2014-12-21 15:23:12 328
原创 Leetcode Wildcard Matching
class Solution {public: bool isMatch(const char *s, const char *p) { char *ss = NULL, *sp = NULL; while(*s){ if(*p=='?'||*s==*p){s++;p++;continue;} if(*p!=
2014-12-21 13:10:21 517
翻译 Leetcode Regular Expression Matching 动态规划解法
class Solution {public: bool isMatch(const char *s, const char *p) { int i, j; int m = strlen(s); int n = strlen(p); /** * b[i + 1][j + 1]: if s[0..i] ma
2014-12-21 06:00:01 3663 4
原创 非递归且最坏情况下仍然为O(n)的第K大数程序
http://acm.hit.edu.cn/hoj/problem/view?id=3137利用上述此题来进行验证,代码如下:#include#include#include#include#include#includeusing namespace std;const int block_size = 5;int findKth(vect
2014-12-20 07:37:49 459
原创 面向对象编程经典例题 --- 收银系统设计
SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported
2014-12-19 11:06:31 2131
原创 面试题---名人识别问题
Celebrity problem: You have a room with n people. A celebrity walks in. Everyone knows the celebrity, the celebrity knows no one. Non-celebrities may/may not know anyone in the room. Give an algor
2014-12-18 13:47:50 713
转载 Leetcode: Divide Two Integers
class Solution {public: int divide(int dividend, int divisor) { long long a = abs((double)dividend); long long b = abs((double)divisor); long long res = 0; i
2014-12-17 05:51:09 283
原创 Leetcode (没有转换long long类型) Fraction to Recurring Decimal
class Solution {public: string fractionToDecimal(int paraNumerator, int paraDenominator) { stringstream integralStream,decimalStream; string integral,decimal; if((paraNume
2014-12-17 05:11:57 551
原创 Leetcode Find Peak Element
class Solution {public: int findPeakElement(const vector &num) { int size = num.size(); if(size==1){ return 0; }else{ int i=0,j=size-1;
2014-12-16 14:56:36 371
原创 Leetcode Read N Characters Given Read4 (I,II同一款程序)
// Forward declaration of the read4 API.int read4(char *buf);const int size = 4;class Solution {private: char buffer[size+1]; int cnt; int readFromBuffer(char *buf, int n){
2014-12-16 14:27:55 583
原创 Leetcode Compare Version Numbers
class Solution {private: int compareNumber(string num1,string num2){ int num1Len = num1.length(), num2Len = num2.length(); if(num1Len > num2Len){ return 1; }e
2014-12-16 12:02:58 368
原创 LeetCode Binary Tree Upside Down
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti
2014-12-16 09:51:27 757
原创 Leetcode Longest Substring with At Most Two Distinct Characters
class Solution {public: int lengthOfLongestSubstringTwoDistinct(string s) { int len = s.length(); unordered_map existingChars; int cnt = 0, longest = 0, st = 0; fo
2014-12-16 07:53:55 442
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人