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
package course.labs.activitylab; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.TextView; |
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
package course.labs.activitylab; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.TextView; |
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
public class Solution { | |
public int minCut(String s) { | |
int n = s.length(); | |
boolean[][] isPalindrome = new boolean[n][n]; | |
for (int i = 0; i < n; i++) | |
isPalindrome[i][i] = true; | |
for (int i = n - 1; i >= 0; i--) { | |
for (int j = i + 1; j < n; j++) { | |
if (s.charAt(i) == s.charAt(j)) { | |
if (j - i < 2 || isPalindrome[i + 1][j - 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
package numberofways; | |
public class numberofways { | |
public static int numberways(int n){ | |
if(n<0){ | |
return 0; | |
} | |
if(n==0){ | |
return -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
public class Question5_8 { | |
public void drawHorizontalLine(byte[] screen, int width, int x1, int x2, int y) { | |
int height = screen.length / (width / 8); | |
if (y < 0 || y >= height || x1 < 0 || x1 >= screen.length * 8 || x2 < 0 || x2 >= screen.length * 8) { | |
return; | |
} | |
int idx = y * (width / 8); | |
int idx1 = idx + (x1 / 8); | |
int idx2 = idx + (x2 / 8); |
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
public class SwapBits { | |
public static int swap(int n) { | |
int EvenBits = 0xAAAAAAAA & n; | |
int OddBits = 0x55555555 & n; | |
return( (OddBits << 1) | (EvenBits >> 1) ); | |
} | |
public static void main(String args[]){ | |
int test = 0b0101110011; | |
System.out.println(Integer.toBinaryString(swap(test))); |
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
public class Q55{ | |
public static void main(String[] args){ | |
int test1= 0b100111010110; | |
int test2= 0b011001000101; | |
System.out.println(numberOfCovert(test1,test2)); | |
} | |
static int bitSwapRequired(int a, int b){ | |
int count=0; | |
int c=a^b; | |
for(c=!0;c=>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
import java.util.*; | |
public class Q54 { | |
public static void main(String[] args){ | |
System.out.println(match2Number(2,4)); | |
} | |
static boolean match2Number(int N,int Number M) { | |
M=N-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
public class Q52 { | |
public static void main(String[] args){ | |
System.out.println(printBinary(0.111111)); | |
System.out.println(printBinary(0.8)); | |
} | |
static String printBinary(double num){ | |
if(num>1 || num<0) | |
return "ERROR"; | |
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
public class BitManipulaation { | |
public static int rewrite(int n, int m,int i, int j){ | |
//to all ones: 11111111111111111111111111111111 | |
int allOne = ~0; | |
//all ones before j, then 0s | |
int left = allOne << (j + 1); | |
//all 0s before i, then 1s | |
int right = ((1 << i) - 1); | |
//all ones, but range i - j are 0s |
NewerOlder