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

刷题记录帖

🔗
 楼主| Oceanid77 2019-10-18 13:59:59 | 只看该作者
全局:
本帖最后由 Oceanid77 于 2019-10-18 14:01 编辑

394. Decode String
done

Find the bug of the following code
class Solution {
    public String decodeString(String s) {
        StringBuilder ans = new StringBuilder();
        Stack<Character> stack = new Stack<>();
        Character[] ch = s.toCharArray();        for(int i=0; i<ch.length; i++){
            Character c = ch;
            if(Character.isDigit(c)||c=='['||Character.isLetter(c)){
                stack.push(c);
            }else{
                StringBuilder helper = new StringBuilder();
                while(stack.peek()!='['){
                    helper.append(stack.pop());
                }
                stack.pop();
                StringBuilder helper1= new StringBuilder();
                StringBuilder num = new StringBuilder();
                while(!stack.isEmpty()&&Character.isDigit(stack.peek())){   
                    num.append(stack.pop());
                }
                 int tag =Integer.parseInt(num.reverse().toString());
                while(tag!=0){
                    helper1.append(helper.toString());
                    tag--;
                }
                String decode = helper1.toString();
                Char[] ch1= decode.toCharArray();

                for(int j=ch1.length-1; j>=0;j--){
                    stack.push(ch1[j]);
                }
            }
        }
        while(!stack.isEmpty()){
            ans.append(Stack.pop()
);
        }
        return ans.reverse().toString();
    }
}
Study another method.
And compare the idea.
Summary for string and character.
150. Evaluate Reverse Polish Notation

回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-20 07:31:36 | 只看该作者
全局:
150. Evaluate Reverse Polish Notation
done
227. Basic Calculator II
another one I dont understand.
224. Basic Calculator
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-20 12:15:53 | 只看该作者
全局:
227. Basic Calculator II
done
224. Basic Calculator

739. Daily Temperatures

CONTEST
Check If It Is a Straight Line

when using / pay attention:
substract 0
a/b*c    和a÷b乘c are different

习惯养成:
不管是什么样的code, 每一次提交之前都要沉住气,检查,至少心里想一个test case,检查基本错误。

前期可能很慢,但是习惯养成之后就会越来越好。
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-21 11:19:32 | 只看该作者
全局:
739. Daily Temperatures
done

Summary of stack
682. Baseball Game
496. Next Greater Element I
844. Backspace String Compare
Integer.valueOf
java.lang.Integer.valueOf(String str) is an inbuilt method which is used to return an Integer object, holding the value of the specified String str.
效率极低, 要怎么办呢?
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-22 12:31:05 | 只看该作者
全局:
What is Binary Search?
why time complexity is O(logn).
https://www.geeksforgeeks.org/co ... s-of-binary-search/
https://www.youtube.com/watch?v=v57lNF2mb_s
69. Sqrt(x)
278. First Bad Version
875. Koko Eating Bananas
378. Kth Smallest Element in a Sorted Matrix
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-23 12:34:16 | 只看该作者
全局:
What is Binary Search?
https://www.geeksforgeeks.org/binary-search/
875. Koko Eating Bananas
int b= a/k;
time+ =a==b*k? b: b+1;
[30,11,23,4,0]
5
why?
287. Find the Duplicate Number
378. Kth Smallest Element in a Sorted Matrix
https://leetcode.com/problems/kt ... and-Clean-Java-Code
350. Intersection of Two Arrays II
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-25 01:39:39 | 只看该作者
全局:
981. Time Based Key-Value Store
392. Is Subsequence
why binary search?
704. Binary Search
done
240. Search a 2D Matrix II
why?

回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-25 13:53:55 | 只看该作者
全局:
162. Find Peak Element
121. Best Time to Buy and Sell Stock
122. Best Time to Buy and Sell Stock II
123. Best Time to Buy and Sell Stock III
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-27 14:52:25 | 只看该作者
全局:
zhouwu
528. Random Pick with Weight
回复

使用道具 举报

🔗
 楼主| Oceanid77 2019-10-27 14:53:32 | 只看该作者
全局:
today mock interview
想一想 min stack 这个题目怎么讲
374. Guess Number Higher or Lower
回复

使用道具 举报

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

本版积分规则

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