15 July 2019
Angular (30) -- Deploying an Angular App
by Jerry Zhang
LeetCode Day 10: P111. Minimum Depth of Binary Tree (Easy)
题目
一个二叉树,找出最小的深度。从根到叶最短路径的节点数。
我的思路:
递归,每个节点的最小深度,都是其左右子节点深度较小的一个加1。如果缺失任意一个子节点,深度就是另一个子节点加1。如果没有子节点,那 深度就是1。
我的代码:
public class E_111_MinimumDepthOfBinaryTree {
public int minDepth(TreeNode root) {
if (root == null) {
return 0;
}
if (root.left == null && root.right == null) {
return 1;
}
if (root.left == null) {
return minDepth(root.right) + 1;
}
if (root.right == null) {
return minDepth(root.left) + 1;
}
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
}
}
最优解:
class Solution {
public int minDepth(TreeNode root) {
if(root == null){
return 0;
}
int res = helper(root);
return res;
}
private int helper(TreeNode root) {
if(root == null){
return 0;
}
int minV = 0;
int left = helper(root.left);
int right = helper(root.right);
if(left != 0 && right != 0){
minV = Math.min(left, right) + 1;
}else {
minV = left == 0 ? (right + 1) : (left + 1);
}
return minV;
}
}
做的事情跟我差不多,但代码可读性很差,感觉不值得学习。这道题比较简单,一次性通过了。
Angular
Deployment Preparation
- Check environment variables.
- Test
- Build
- Deploy build artifacts to static host
Environment Variables
In the src folder, there is a environments folder. There are two files in it.
We can add key value pairs to that const.
export const environment = {
production: false,
firebaseAPIKey: 'weoifujklxdfnkhf'
};
Then we need to import this environment in the file that is using this API key.
import { environment } from '../../environment';
'...?key=' + environment.firebaseAPIKey,
Firebase Hosting
Install firebase cli
npm install -g firebase-tools
Go to the npm folder to run firebase
command
cd C:\Users\I505998\AppData\Roaming\npm
And set this path as an environment variable in Windows System.
firebase login
firebase init
Are you ready to proceed? Yes
Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices.
Hosting: Configure and deploy Firebase Hosting sites
Select a default Firebase project for this directory: recipebook-cc2b1 (RecipeBook)
What do you want to use as your public directory? dist/RecipeBook
Configure as a single-page app (rewrite all urls to /index.html)? Yes
File dist/RecipeBook/index.html already exists. Overwrite? No
firebase deploy