invincibleveer
BAN USERswapKthNode(node *head){
temp=head
while(k!=1){
if (head == NULL) return "ERROR";
head = head->next;
k--;
}
first_node=head;
while(head->next!=NULL){
head = head->next;
temp = temp->next;
}
second_node = temp;
swap(first_node->data, second_node->data)
}
def getCount(item_list):
hash_map = {}
for each in item_list:
hash_map[each] += 1
A working Python Code
def getPairForSumN(item_list, N):
hash_map = {}
set_pair = set([])
count = 0
for item in item_list:
hash_map[item] = N-item
for k,v in hash_map.items():
if hash_map.get(k,None) is not None and hash_map.get(hash_map.get(k, None) ) is not None:
half_count = 0
if N%2 == 0 and k == N/2:
for each in item_list:
if each == k:
half_count += 1
if half_count >=2:
set_pair.add((k,v))
else:
set_pair.add((k,v))
hash_map.pop(k)
count += 1
return set_pair
hash_map = { }
def removeDuplicate(root):
if hash_map.get(root->data):
print "Found duplicate"
swap(root->data, heaps(last_element) )
delete(heaps(last_element) )
min_heapify(root)
else:
hash_map.put(root->data, True)
removeDuplicate(root->left)
removeDuplicate(root->right)
@oshin Can u plz explain how did u come up with expression?
- invincibleveer July 16, 2010can anyone provide working code/psuedocode?
- invincibleveer July 09, 2010
- invincibleveer July 21, 2012