Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int removeDuplicates(int[] nums) { | |
int len = nums.length; // calculate length of the array. | |
if(len == 0 || len == 1)return len; // return length if array has zero or only one element. | |
int lastMem = nums[0]; // stores the element that is not duplicate | |
int count = 1; //return count at last so as to get the unique element count | |
int index = 1; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* C++ program to find Inorder successor in a BST */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *left; | |
struct Node *right; | |
}; | |
//Function to find some data in the tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Deleting a node from Binary search tree */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *left; | |
struct Node *right; | |
}; | |
//Function to find minimum in a tree. | |
Node* FindMin(Node* root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Pseudo code to check whether a binary tree is Binary Search Tree or not | |
bool checkBST(Node* root,int min,int max){ | |
if(root == NULL)return true; | |
if(root->data > min && root->data < max && checkBST(root->left,min,root->data) && checkBST(root->right,root->data,max)) | |
return true; | |
else return false; | |
} | |
isBST(Node* root){ | |
return checkBST(root, INT_MIN, INT_MAX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Binary Tree Traversal - Preorder, Inorder, Postorder */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
char data; | |
struct Node *left; | |
struct Node *right; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Binary tree - Level Order Traversal */ | |
#include<iostream> | |
#include<queue> | |
using namespace std; | |
struct Node { | |
char data; | |
Node *left; | |
Node *right; | |
}; |
NewerOlder