zoukankan      html  css  js  c++  java
  • done apple经理面 匹配括号但是不能用stack

    一个感想:面试真是有效学习的唯一途径。面试前觉得自己啥都会,面完了才发觉自己是个知识有漏洞的傻逼。

    有面试才有学习机会,先拿到面试,之后啥都好说。

    {[abc]}[ab]{}
    no stack, use loop
    一开始抄了一个c++的答案错了,cnm。。。血的教训:不要抄别的语言的答案!
    后来抄了一个只有括号的答案,要改,时间来不及了。。

     

    from Abhishek Shukla (Apple) to Everyone:    12:15  PM
    public class A {
        protected A() {
            print("inside A");
        }
    }
    public class B extends A {
        protected B() {
            print("inside B");
        }
        
        main () {
            A a = new B();
        }
    }
    from Abhishek Shukla (Apple) to Everyone:    12:18  PM
    =======================
    from Abhishek Shukla (Apple) to Everyone:    12:18  PM
    Class A {
        void method1(int i){
            print("inside A.method1");
        }
    }
    
    
    Class B extends A {
        void method1(int i){
            print("inside B.method1 with int");
        }
        
        void method1(String s){
            print("inside B.method1 with String");
        }
        
        main () {
            A a = new B();
            a.method1(10);
        }
    }
    from Abhishek Shukla (Apple) to Everyone:    12:21  PM
    ======================
    from Abhishek Shukla (Apple) to Everyone:    12:21  PM
    public class Myclass {
       private static Integer INT = new Integer(10);
        public synchronized void methodA () {
            print("Inside method A")
        }
        public synchronized static void methodB () {
            print("Inside method B")
        }
    }
    
    from Abhishek Shukla (Apple) to Everyone:    12:15  PM
    public class A {
        protected A() {
            print("inside A");
        }
    }
    public class B extends A {
        protected B() {
            print("inside B");
        }
        
        main () {
            A a = new B();
        }
    }
    from Abhishek Shukla (Apple) to Everyone:    12:18  PM
    =======================
    from Abhishek Shukla (Apple) to Everyone:    12:18  PM
    Class A {
        void method1(int i){
            print("inside A.method1");
        }
    }
    
    
    Class B extends A {
        void method1(int i){
            print("inside B.method1 with int");
        }
        
        void method1(String s){
            print("inside B.method1 with String");
        }
        
        main () {
            A a = new B();
            a.method1(10);
        }
    }
    
    
    
    
    
    
    
    
    
    from Abhishek Shukla (Apple) to Everyone:    12:15  PM
    
    public class A {
        protected A() {
            print("inside A");
        }
    }
    public class B extends A {
        protected B() {
            print("inside B");
        }
        
        main () {
            A a = new B();
        }
    }
    import java.util.*;
    
    public class MyClass {
        
        public static void main(String args[]) {
          String s = "{[abc]}[ab]{}";
          boolean result = "true";
          
          //use array
          char[] array = s.toCharArray();
          
          int pointer = 0;
          char[] helper = new char[array.length];
    
           //for loop 
           for (char c: array) {
               if (c == '(') helper[pointer++] = ')';
               else if (c == '{') helper[pointer++] = '}';
               else if (c == '[') helper[pointer++] = ']';
               
               //check 
               else if (pointer == 0 || helper[--pointer] != c) {
                   result = "false";
               }
           }
           
          //judge if pointer can always be 0
          if (pointer == 0) 
            System.out.println("true");
          else
            System.out.println("false");
          
        }
    }
        //time:n, space:n
        

     

  • 相关阅读:
    面试总结
    CentOS 6.4 yum安装LAMP环境
    windows下XAMPP安装php_memcache扩展
    linux学习笔记
    本地虚拟机LNMP环境安装
    Linux下php安装memcache扩展
    linux下memcached安装以及启动
    阿里云服务器---centos编译安装ffmpeg
    [Yii2.0] 以Yii 2.0风格加载自定义类或命名空间 [配置使用Yii2 autoloader]
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/immiao0319/p/15350982.html
Copyright © 2011-2022 走看看