📣 4th of July限时特惠: VIP通行证立减$68
楼主: 车车车车车
跳转到指定楼层
上一主题 下一主题
收起左侧

刷题打卡

🔗
 楼主| 车车车车车 2018-8-23 02:36:33 | 只看该作者
全局:
本帖最后由 车车车车车 于 2018-8-23 06:56 编辑

445. Add Two Numbers II
                int sum = 0;
                ListNode temp = null;
                while (!stack1.isEmpty() || !stack2.isEmpty()) {
                        if (!stack1.isEmpty()) {
                                sum += stack1.pop();
                        }
                        if (!stack2.isEmpty()) {
                                sum += stack2.pop();
                        }
        
                        ListNode head = new ListNode(sum % 10);
                        head.next = temp;
                        temp = head;
                        sum = sum / 10;               
                }
                if (sum == 1) {
                        ListNode head = new ListNode(1);
                        head.next = temp;
                        temp = head;
                }
                return temp;        



//从头节点开始插入
ListNode insertHead (ListNode head, LIstNode node) {
           node.next = head;
           head = node;
           return head;

}


105. Construct Binary Tree from Preorder and Inorder Traversal


106. Construct Binary Tree from Inorder and Postorder Traversal
//递归调用注意起始index


TreeNode helper(int[] inorder, int inSta, int inEnd, int[] postorder, int postSta, int postEnd) {
                if (inSta > inEnd || postSta > postEnd) {
                        return null;
                }
                int mid = 0;
                for (int i = inSta; i <= inEnd; i++) {
                        if (inorder[i] == postorder[postEnd]) {
                                mid = i;
                                break;
                        }
                }
                TreeNode res = new TreeNode(inorder[mid]);
                res.left = helper(inorder, inSta, mid - 1, postorder, postSta, postSta + mid - inSta - 1);
                res.right = helper(inorder, mid + 1, inEnd, postorder, postSta + mid - inSta, postEnd - 1);
                return res;
        }

回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-8-27 01:01:10 | 只看该作者
全局:
98. Validate Binary Search Tree
//注意整数型溢出 long
99. Recover Binary Search Tree

103. Binary Tree Zigzag Level Order Traversal
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-8-30 05:44:40 | 只看该作者
全局:
Combination Sum 1234
套路满满啊一个dp一个dfs
public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 1; i <= target; i++) {
            for (int num : nums) {
                if (num <= i) {
                    dp[i] += dp[i - num];
                }
            }
        }
        return dp[target];
    }



void helper(int[] candidates, int target, int start, List<List<Integer>> res, List<Integer> list) {
                 if (target < 0) {
                         return;
                 }
                 if (target == 0) {
                         res.add(new ArrayList<>(list));
                 }
                 for (int i = start; i < candidates.length; i++) {
                         if (i > start && candidates[i] == candidates[i - 1]) {
                                 continue;
                         }
                         list.add(candidates[i]);
                         helper(candidates, target - candidates[i], i + 1, res, list);
                         list.remove(list.size() - 1);
                 }
         }
===== 最近掉坑里了  。。
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-8-31 11:14:30 | 只看该作者
全局:
My Calendar 123.。。。
==
=====。========
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-9-6 06:32:51 | 只看该作者
全局:
695. Max Area of Island
200. Number of Islands
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-9-13 22:20:09 | 只看该作者
全局:
22. Generate Parentheses
20. Valid Parentheses
32. Longest Valid Parentheses
241. Different Ways to Add Parentheses
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-9-16 06:14:03 | 只看该作者
全局:
129. Sum Root to Leaf Numbers
109. Convert Sorted List to Binary Search Tree
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-9-24 10:24:46 | 只看该作者
全局:
Maximum Width of Binary Tree
Letter Combinations of a Phone Number
Permutations 1, 2
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-10-1 01:07:29 | 只看该作者
全局:
        Merge Intervals
        Insert Interval
Find First and Last Position of Element in Sorted Array
        Maximize Distance to Closest Person

这两天有个心得 想不明白的问题不如暂时先放一放 说不定洗个澡回来就发现想明白了
有一个小愿望~
回复

使用道具 举报

🔗
 楼主| 车车车车车 2018-10-17 00:53:21 | 只看该作者
全局:
44. Wildcard Matching
49. Group Anagrams
回复

使用道具 举报

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

本版积分规则

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