lintcode:
http://lintcode.com/en/problem/singleton/
Java
class Solution {
public static Solution instance = null;
/**
* @return: The same instance of this class every time
*/
public static Solution getInstance() {
// write your code here
if (instance == null) {
instance = new Solution();
}
return instance;
}
};
Python
class Solution:
instance = None
# @return: The same instance of this class every time
@classmethod
def getInstance(cls):
# write your code here
if cls.instance == None:
cls.instance = Solution()
return cls.instance