This file contains hidden or 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 com.jomarpueyo; | |
import java.util.Scanner; | |
public class Section5 { | |
public static void main(String[] args) { | |
//Exercise 11 | |
System.out.println("Exercise 11"); | |
printNumberInWord(0); |
This file contains hidden or 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 Section4 { | |
public static void main(String[] args) { | |
//Coding Exercise 1 | |
System.out.println("Exercise 1"); | |
printMegaBytesAndKiloBytes(-1020); | |
printMegaBytesAndKiloBytes(1020); | |
printMegaBytesAndKiloBytes(2050); | |
//Coding Exercise 2 |
This file contains hidden or 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 boolean isPalindrome(int x) { | |
if(x<0){ | |
return false; | |
} | |
char [] xArray = (""+x).toCharArray(); | |
for(int i=0; i<xArray.length/2;i++){ | |
if(xArray[i]!=xArray[xArray.length-1-i]){ | |
return false; | |
} |
This file contains hidden or 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 romanToInt(String s) { | |
Map<Character, Integer> map = new HashMap<>(); | |
map.put('I',1); | |
map.put('V',5); | |
map.put('X',10); | |
map.put('L',50); | |
map.put('C',100); | |
map.put('D',500); | |
map.put('M',1000); |
This file contains hidden or 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 String reverseString(String s) { | |
char [] sArray = s.toCharArray(); //Convert String to char[] Array | |
int swaps = sArray.length/2; //Find how many swaps (Odds round down) | |
int i = 0; //Index of character we are on | |
for (swaps = swaps; swaps!=0 ; swaps--){ | |
char copy = sArray[i]; //Make a copy before over written | |
sArray[i] = sArray[sArray.length - 1 - i]; //Overwrite copy | |
sArray[sArray.length - 1 - i] = copy; //Set copy to swap position | |
i++; //Increment index |
This file contains hidden or 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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
class Solution { |
This file contains hidden or 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
from random import shuffle | |
import sys | |
def main(): | |
#sys.setrecursionlimit(9000) #system recursion limit | |
array_size = 7 #Number of Items in the list | |
myList=[] #Initialize List | |
for i in range(array_size): #Create List of User Input | |
myList.append(i+1) #Add item to list |
This file contains hidden or 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 numJewelsInStones(String J, String S) { | |
char [] jArray = J.toCharArray(); //Prep both strings to be searched | |
char [] sArray = S.toCharArray(); | |
int count = 0; | |
for(char x : jArray){ //For every element in jArray, | |
for (char y : sArray){ //search in the sArray. |