-
Notifications
You must be signed in to change notification settings - Fork 5
/
ExcelSheetColumnTitle.java
52 lines (45 loc) · 1.37 KB
/
ExcelSheetColumnTitle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Problem Statement:
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
Problem Link:
Excel Sheet Column Title: https://leetcode.com/problems/excel-sheet-column-title/description/
Solution:
https://github.com/sunnypatel165/leetcode-again/blob/master/solutions/ExcelSheetColumnTitle.java
Author:
Sunny Patel
https://github.com/sunnypatel165
https://www.linkedin.com/in/sunnypatel165/
*/
class Solution {
public boolean isBalanced(TreeNode root) {
if(root==null)
return true;
if(Math.abs(maxDepth(root.left) - maxDepth(root.right))>1)
return false;
return isBalanced(root.left) && isBalanced(root.right);
}
public int maxDepth(TreeNode root) {
if(root==null)
return 0;
if(root.left==null && root.right == null){
return 1;
}
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
class Solution {
public String convertToTitle(int n) {
StringBuilder builder = new StringBuilder();
while(n>0){
if(n%26==0){
builder.append((char)('Z')+"");
n--;
}
else
builder.append((char)(n%26+'A'-1)+"");
n/=26;
}
return builder.reverse().toString();
}
}