var twoSum = function(nums, target) {
var numset = {};
var res = [];
for(var i = 0; i<nums.length; i++)
{
if(numset[targetnums[i]] != undefined)
{
res.push(numset[targetnums[i]]);
res.push(i);
return res
}
else
{
numset[nums[i]]=i;
}
}
};
zjh08177
@zjh08177
Posts made by zjh08177

AC javascript solution

RE: C++ post referred to top voted post
Haha, that's my idea initially. @vinceyuan made it more readable. ^ ^

RE: 0ms concise C++ solution (perfectly handles the followup and leading 0s)
Hi petooo, this is used to prevent such case like (12123, since the size of '3' is less than the size of '12+12', we end this search). This if condition works as an early pruning method.

RE: My elegant recursive C++ solution with inline explanation
The second swap will cause failing test cases in Permutations II

RE: My elegant recursive C++ solution with inline explanation
The second swap is useless since we will always generate all permutations of the sublists. So we don't need to do the recover process.

RE: Adding Two Lines to Permutation I, Why got Output Limit Exceed?
First sort the original list.
Second (which I confused for a while), you should not do the second swap to recover. Because this will cause you next list not be sorted. (this is what different from Permutations I, actually, the second swap is also useless in Permutations I since we will always generate all permutations of the sublists, the the recovering process is needless.)

RE: O(k) space, O(n) time, 10+ short lines, 3 solutions
I'm using morris traversal for this problem and kth closet element in BST and always return a RUNTIME ERROR. Now I know why. Thank you so much!

Why my Morris Traversal code return 'Runtime error'??
I use morris traversal to find kth elements of a BST. The code works fine on my local machine but return Runtime Error (test case: [2,1],1) on OJ. Could someone help me figure out why? Thanks in advance.
int kthSmallest(TreeNode* root, int k) { TreeNode* cur=root; while(k && cur){ TreeNode* nxt=cur>left; if(!nxt){ if(k==1) break; cur=cur>right; } else{ while(nxt>right && nxt>right!=cur) nxt=nxt>right; if(!nxt>right){ nxt>right=cur; cur=cur>left; } else{ nxt>right=NULL; if(k==1) break; cur=cur>right; } } } return cur>val; }

What about the tail node is considered?
if we are going to delete the tail node and only given that node, how could we do that??

RE: Here is a 10line template that can solve most 'substring' problems
Thank you very much. Actually I'm inspired by the solutions here and then find out a general one.