楼主: LadyAndBird
跳转到指定楼层
上一主题 下一主题
收起左侧

生物转 CS 学习打卡贴

🔗
 楼主| LadyAndBird 2017-10-17 17:01:37 | 只看该作者
全局:
10/16/2017 Mon
Started a new course on best practices in JS. Finished level 1.
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-10-18 16:29:03 | 只看该作者
全局:
10/17/2017 Mon
Finished level 2.
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-10-22 15:42:00 | 只看该作者
全局:
10/21/2017 Sat
Finished level 3.
这几天各种事情乱七八糟的搞得好焦虑。。无心学习。。sigh。。。需要赶快调整心态,打打鸡血!!
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-10-27 06:32:22 | 只看该作者
全局:
本帖最后由 LadyAndBird 于 2017-10-27 06:35 编辑

10/26/2017 Thu
Finally finished all levels in this course...
Starting new course on React.
感慨一下 js code 真是各种乱啊。。突然开始怀念 Java 了。。虽然罗里吧嗦的。。好歹逻辑比较清楚。。(捂脸。。

回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-3 00:06:37 | 只看该作者
全局:
11/02/2017 Thu
Been out of town these days... didn't study much.
Learned jQuery a bit yesterday. Cleared several concepts. Not bad.
Planning to start a project maybe in a few days.
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-8 14:37:58 | 只看该作者
全局:
本帖最后由 LadyAndBird 于 2017-11-8 14:47 编辑

这几天学了点儿jQuery,虽然比较过时了,但是code school的课里面讲了些 js 的基础知识。。之前想直接跳到 react 的课结果好些术语不懂。。只好又回头去看之前的课。。(捂脸
今天加了个小刷题群,每天一道,有大牛带着还是很爽的说。。对于拖延症很有效。。因为三天不刷就踢出去了。。(捂脸
今天刷了一道 rotateMatrix,不难,但是很久没写 Java 了各种报错哈哈哈。。ps,还是决定用 Java 刷题了,虽然语法很啰嗦,但是感觉比较straight forward。。而且 Java 都忘得差不多了,也是时候捡起来了。。加油加油!

import java.io.*;
import java.util.*;

class Solution {

  public static void rotateMatrix(int[][] m, int s) {
    for (int i=0; i<s/2; i++){
      for (int j=0; j<(int)Math.ceil((float)s/2); j++){
        int temp = m[j];
        m[j] = m[s-j-1];
        m[s-j-1] = m[s-i-1][s-j-1];
        m[s-i-1][s-j-1] = m[j][s-i-1];
        m[j][s-i-1] = temp;                       
      }
    }  
  }

  public static void printMatrix(int[][] m){
    for (int i=0; i<m.length; i++){
      for (int j=0; j<m.length; j++){
        if (j == m.length-1){
          System.out.println(m[j]);
        } else {
          System.out.print(m[j] + ", ");  
        }        
      }
    }
    System.out.println();
  }

public static void main(String[] args) {
    int[][] matrix = {
      {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}
    };

    printMatrix(matrix);
    rotateMatrix(matrix, matrix.length);
    printMatrix(matrix);
  }
}



回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-9 15:05:18 | 只看该作者
全局:
2017/11/08
easy

import java.io.*;
import java.util.*;

class Solution {
  public static void main(String[] args) {
    ArrayList<String> strings1 = new ArrayList<String>();
    strings1.add("AAABB");
    strings1.add("AABCC");
    strings1.add("AB");
    for (String string : strings1) {
      System.out.println(string);
      System.out.println(decode(string));
    }
    ArrayList<String> strings2 = new ArrayList<String>();
    strings2.add("3A2B");
    strings2.add("2A1B2C");
    strings2.add("1A1B");
    for (String string : strings2) {
      System.out.println(string);
      System.out.println(encode(string));
    }
  }
  
  public static String decode(String s) {
    // AAABBB -> 3A2B
    // ABABBBB -> ABA4B
    String[] parts = s.split("");
    String prev = parts[0];
    int count = 0;
    String result = "";
    for (String curr : parts){
      if (Objects.equals(curr, prev)){
        count++;
      } else {        
        result += count + prev;
        prev = curr;
        count = 1;
      }
    }
    result += count + prev;
    return result;
  }
  
  public static String encode(String s) {
    String[] parts = s.split("");
    String result = "";
    for (int i = 0; i < parts.length; i += 2){
      for (int j = 0; j < Integer.parseInt(parts[i]); j++){
        result += parts[i+1];
      }
    }
    return result;
  }
  
}

回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-10 14:46:55 | 只看该作者
全局:
11/09/2017
My first 2 binary binary tree problems... maxDepth and minDepth.
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-12 16:23:38 | 只看该作者
全局:
更新一下昨天的进度,又学了点儿tree相关的,做了一道找两个Node之间distance的题,写了两个解法,一个是binary search tree的一个是普通binary tree的,还挺开心的,要知道在昨天之前我连binary search tree是什么都不知道哈哈哈。。。这几天每天刷一道题,我的算法几乎0基础,基本上什么都是现学的,但是自己琢磨出来解法并实现成功的感觉真好,每天都在进步的感觉真爽!

import java.io.*;
import java.util.*;

class Solution {
  
  public static class Node {
    int val;
    Node left;
    Node right;
    Node(int value) {
      val = value;
    }
  }
  public static void main(String[] args) {
   
    /*
            4
          2   6
        1  3
      0
    */
    Node root = new Node(4);
    root.left = new Node(2);
    root.right = new Node(6);
    root.left.left = new Node(1);
    root.left.right = new Node(3);
    root.left.left.left = new Node(0);
   
    System.out.println(getDistance(root.left.left.left, root.left.right, root));
   
    System.out.println(getDistance2(root.left.left.left, root.left.right, root));
   
  }
  
// General binary tree
  public static int getDistance2(Node A, Node B, Node root) {
    Stack<Node> aPath = getPath(A, root);
    Stack<Node> bPath = getPath(B, root);
   
    int distance = 0;
    while (!aPath.empty() || !bPath.empty()){
      if (aPath.empty()) {
        bPath.pop();
        distance++;
      } else if (bPath.empty()) {
        aPath.pop();
        distance++;
      } else {
        if (aPath.pop() != bPath.pop()) { distance += 2; }
      }
    }

    return distance;
  }
  
  public static Stack<Node> getPath(Node node, Node root) {
    Stack<Node> path = new Stack<Node>();
    findNode(node, root, path);
    return path;
  }
  
  public static boolean findNode(Node node, Node root, Stack<Node> path) {
    if (root != null) {
      if (node == root || findNode(node, root.left, path) || findNode(node, root.right, path)) {
        path.push(root);
        return true;
      } else return false;
    } else return false;
  }
  
// Binary search tree
  public static int getDistance(Node A, Node B, Node root) {
    Node parent = getParent(A, B, root);
    return getDistance(A, parent) + getDistance(B, parent);
  }
  
  public static Node getParent(Node A, Node B, Node root) {
    if (A.val == root.val || B.val == root.val) return root;
    if ((A.val - root.val) * (B.val - root.val) < 0) return root;
    if (A.val < root.val) {
      return getParent(A, B, root.left);
    } else {
      return getParent(A, B, root.right);
    }   
  }
  
  public static int getDistance(Node A, Node parent) {   
    if (A.val == parent.val) return 0;
    if (A.val < parent.val) {
      return getDistance(A, parent.left) + 1;
    } else {
      return getDistance(A, parent.right) + 1;
    }
  }
}
回复

使用道具 举报

🔗
 楼主| LadyAndBird 2017-11-13 14:58:31 | 只看该作者
全局:
11/12/2017 Sun
刷了一道 OA 真题,很好玩儿。

补充内容 (2017-11-15 04:20):
11/13/2017 Mon
1 easy tree problem
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表