690. Employee Importance

690. Employee Importance

/*
// Employee info
class Employee {
    // It's the unique id of each node;
    // unique id of this employee
    public int id;
    // the importance value of this employee
    public int importance;
    // the id of direct subordinates
    public List subordinates;
};
*/
class Solution {
	public Employee getEmployeeById(List employees, int id1) {
		for (int i = 0; i < employees.size(); i++) {
			if (employees.get(i).id == id1)
				return employees.get(i);
		}
		return null;
	}

	public int getImportance(List employees, int id) {
		int result = 0;
		Employee current = getEmployeeById(employees, id);
		result += current.importance;

		if (current.subordinates == null || current.subordinates.size() == 0)
			return result;

		for (int i = 0; i < current.subordinates.size(); i++)
			result += getImportance(employees, current.subordinates.get(i));

		return result;

	}
}

520. Detect Capital

520. Detect Capital

class Solution {
    	public boolean detectCapitalUse(String word) {
		if (Character.isLowerCase(word.charAt(0))) {
			if (isAllLowerCase(word.substring(1)))
				return true;
		} else {
			if (isAllLowerCase(word.substring(1)) || isAllUpperCase(word.substring(1)))
				return true;
		}
		return false;
	}

	public boolean isAllLowerCase(String word) {
		for (int i = 0; i < word.length(); i++) {
			if (Character.isUpperCase(word.charAt(i)))
				return false;
		}
		return true;
	}

	public boolean isAllUpperCase(String word) {
		for (int i = 0; i < word.length(); i++) {
			if (!Character.isUpperCase(word.charAt(i)))
				return false;
		}
		return true;
	}
}