Skip to content

Instantly share code, notes, and snippets.

View vple's full-sized avatar

Vincent vple

  • Brooklyn, New York
View GitHub Profile
// Approach 1: if/else chain. (This could also be a switch.)
public static String digit2String(int digit) {
if (digit == 0) {
return "0";
} else if (digit == 1) {
return "1";
} else if (digit == 2) {
return "2";
} else if (digit == 3) {
return "3";
public static String int2String(int n) {
List<String> digits = new ArrayList<>();
while (n > 0) {
int digit = n % 10;
digits.add(digit2String(digit));
n = n / 10;
}
// To be implemented...
public static String int2String(int n) {
while (n > 0) {
int digit = n % 10;
n = n / 10;
}
// To be implemented...
}
public static String int2String(int n) {
int power = 0;
int nCopy = n;
while (nCopy > 0) {
power++;
nCopy = nCopy / 10;
}
// 10^power is one order higher than what we want.
power--;
public static void int2String(int n) {
return Integer.toString(n);
}
public static void int2String(int n) {
return "" + n;
}
import java.io.*;
import java.util.*;
/*
*/
class Solution {
// Implement me!
static String int2String(int n) {
if (n == 0) {
while (itemIdx < item.size()) {
Map itm = (Map)(item.get(itemIdx));
//ensure both itm and nextItem contain externalId - i.e the NS product mapping
if (itm.containsKey("item") && itm["item"].containsKey("externalId") &&
nextItem.containsKey("item") && nextItem["item"].containsKey("externalId")) {
//find which invoice item nextItem should be applied to
appliedToItemId = record.get("InvoiceItem.AppliedToInvoiceItemId");
//System.out.println("Itm ext id:" + itm["item"]["externalId"] + ", Applied to Id:" + appliedToItemId);
//if ((itm["item"]["externalId"] != null) && itm["item"]["externalId"].equals(appliedToItemId)) {
//add amount to existing
while (itemIdx < item.size()) {
Map itm = (Map)(item.get(itemIdx));
//ensure both itm and nextItem contain externalId - i.e the NS product mapping
if (itm.containsKey("item") && itm["item"].containsKey("externalId") &&
nextItem.containsKey("item") && nextItem["item"].containsKey("externalId")) {
//find which invoice item nextItem should be applied to
appliedToItemId = record.get("InvoiceItem.AppliedToInvoiceItemId");
//System.out.println("Itm ext id:" + itm["item"]["externalId"] + ", Applied to Id:" + appliedToItemId);
//if ((itm["item"]["externalId"] != null) && itm["item"]["externalId"].equals(appliedToItemId)) {
//add amount to existing