copy importjava.io.*; classGFG{ // function to check whether // the bit at given position // is set or unset staticintbitAtGivenPosSetOrUnset (intn,intk) { // to shift the kth bit // at 1st position intNew_num=1<<(k-1); ...
importjava.io.*; importjava.util.*; // Main class classGFG{ // Main driver method publicstaticvoidmain(String[]args) { // Random array of string as input Stringgfg[]={"Are","You","A","Programmer"}; Stringgfg2=""; // Creating object of StringBuilder class ...
importjava.util.*; importjava.io.*; classGFG{ publicstaticvoidmain(String[]args){ BST tree=newBST(); tree.insert(30); tree.insert(50); tree.insert(15); tree.insert(20); tree.insert(10); tree.insert(40); tree.insert(60); tree.inorder(); } } classNode{ Node left; intval; Nod...
// Java program to find median importjava.util.*; classGFG{ // Function for calculating median publicstaticdoublefindMedian(inta[],intn) { // First we sort the array Arrays.sort(a); // check for even case if(n%2!=0) return(double)a[n/2]; ...
// Java program to find minimum number of // flip to make binary string alternate classGFG { // Utility method to flip a character publicstaticcharflip(charch) { return(ch=='0')?'1':'0'; } // Utility method to get minimum flips when // alternate string starts with expected char ...
importjava.util.*; classGFG { // Returns count of pairs in arr[0..n-1] with XOR // value equals to x. staticintxorPairCount(intarr[],intn,intx) { intresult=0;// Initialize result // create empty map that stores counts of ...
importjava.io.*; classGFG { staticintAdd(intx,inty) { // Iterate till there is no carry while(y!=0) { // carry now contains common // set bits of x and y intcarry=x&y; // Sum of bits of x and // y where at least one ...
importjava.io.*; importjava.util.*; // 2-pointer Approach of Word Break Problem classGFG{ // The solution function publicstaticintwordBreak(StringA, ArrayList<String>B) { // store two pointers to start with inti=0, j=1; // store the length of the String to be segmented ...
importjava.lang.*; importjava.io.*; classGFG { publicstaticvoidmain(String[]args) { Scanner dis=newScanner(System.in); Strings1="",s2=""; intt=0,l=0,i=0,j=0,w1=0,w2=0; t=dis.nextInt(); for(i=0;i<t;i++) { s1=dis.next(); ...
Java (HotSpot 12) created: 4 years ago 可見度: public Share or Embed source code Discover >Sphere Engine API The brand new service which powers Ideone! Discover >IDE Widget Widget for compiling and running the source code in a web browser!