806. Number of Lines To Write String

806. Number of Lines To Write String

class Solution {	public int[] numberOfLines(int[] widths, String S) {

		int currentChar = 0;
		if (S.length() == 0) return new int[]{0,0};
		int lines = 1;

		for (int i = 0; i < S.length(); i++) {
			currentChar += widths[S.charAt(i) - 97];
			if( currentChar > 100){
				currentChar -= widths[S.charAt(i) - 97];
				currentChar = widths[S.charAt(i) - 97];
				lines++;
			}else if( currentChar == 99 && i < S.length() - 1 /*at least there is one following char*/){
				currentChar = 0;
				lines++;
			}
		}

		return new int[] { lines, currentChar};

	}}

811. Subdomain Visit Count

811. Subdomain Visit Count

import java.util.Hashtable;
public static List subdomainVisits(String[] cpdomains) {
		List out = new ArrayList();

		Hashtable totals = new Hashtable();

		for (int i = 0; i < cpdomains.length; i++) {
			String[] cpDomainsSplit = cpdomains[i].split(" ");
			String visits = cpDomainsSplit[0];
			String cpdomain = cpDomainsSplit[1];

			String[] parts = cpdomain.split("\\.");

			
			for (int x = 0; x = 0; j--) {
				String currentPart = "";
				for (int k = j; k < parts.length; k++) {
					currentPart += (parts[k]);
				}
				if (totals.get(currentPart) != null) {
					int exist = totals.get(currentPart);
					totals.replace(currentPart, totals.get(currentPart) + new Integer(visits));
				} else
					totals.put(currentPart, new Integer(visits));
			}

		}
		for (String key : totals.keySet()) {
			out.add(totals.get(key) + " " + key);
		}
		return out;
	}

728. Self Dividing Numbers

728. Self Dividing Numbers

class Solution {
	public static boolean isSelfDividing( int i){
		for ( int x = i ; x > 0 ; x /=10){
			int m = x % 10;
			if( m == 0 /*to avoid i%0*/|| i % m != 0) return false;
		}
		return true;
	}
    public List selfDividingNumbers(int left, int right) {
    	List out = new ArrayList();
    	
    	for ( int i = left ; i <= right ; i++ ){
    		if ( isSelfDividing(i)) out.add(i);
    	}
    	return out;
    }
}