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 MockTest { | |
public static int bigDiff(int[] nums) { | |
int max = nums[0]; | |
int min = nums[0]; | |
for (int i = 1; i < nums.length; i++) { | |
int n = nums[i]; |
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 LabAssessmentQ1 { | |
public static int[] withoutTen(int[] nums){ | |
int j = 0; | |
for (int i = 0; i < nums.length; i++) { | |
int n = nums[i]; | |
nums[i] = 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
package hk.edu.cityu.ast10106.gp12.inventory.ui; | |
import org.eclipse.jface.viewers.TableViewer; | |
import org.eclipse.jface.viewers.Viewer; | |
import org.eclipse.jface.viewers.ViewerComparator; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.widgets.Table; | |
import org.eclipse.swt.widgets.TableColumn; | |
/** |
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 BottleShop { | |
private String answer = "a secret"; | |
public int changeEmptyBottlesToDrinks(int emptyBottles) { | |
int drinks; | |
if (emptyBottles == 10) { | |
drinks = 1; | |
} else { |
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
// Write a C++ program to simulate Mark Six lottery game. | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <ctime> | |
using namespace std; | |
int main() |
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
#include <string> | |
// Converts string of decimal digits to numeric type. | |
template <class T> | |
T sto(const std::string & s) | |
{ | |
T t = 0; | |
for (const char c : s) | |
t = t * 10 + c - '0'; | |
return t; |
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
// Hi! I'm going to show you how to write a Java program that outputs the sum | |
// of two given numbers. I will assume that this is your first time programming | |
// and try to explain as much as possible. | |
// Before we get started, any text that follows two consecutive backslashes is | |
// called a "comment". You are reading a comment right now. Comments are for | |
// documenting code and will be completely ignored by the computer. | |
// Ok, let's get into it. In order to read values from input, we must import | |
// Scanner: |
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 static void main(String[] args) { | |
In in = new In(args[0]); | |
int n = in.readInt(); | |
int[][] blocks = new int[n][n]; | |
for (int i = 0; i < n; ++i) | |
for (int j = 0; j < n; ++j) | |
blocks[i][j] = in.readInt(); | |
Board initial = new Board(blocks); | |
Solver solver = new Solver(initial); | |
if (solver.isSolvable()) { |
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
#include <limits> | |
#include <iostream> | |
using namespace std; | |
// The double comparison function, exactly as provided in the tutorial | |
bool compareDoubleEqual(double val1, double val2) { | |
if(abs(val1 - val2)<2.0*std::numeric_limits<double>::epsilon()) | |
return true; | |
else |
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 UpperBound { | |
public static int upperBound(String[] words, int lo, int hi, String word) { | |
while (lo < hi) { | |
int mid = lo + (hi - lo >> 1); | |
String other = words[mid]; | |
int toffset = word.length() - 2; | |
int ooffset = other.length() - 2; | |
if (word.regionMatches(toffset, other, ooffset, 2)) | |
lo = mid + 1; |
OlderNewer