微软 Leetcode

文章目录

1. Two Sum

3. Longest Substring Without Repeating Characters

5. Longest Palindromic Substring

23. Merge k Sorted Lists

25. Reverse Nodes in k-Group

41. First Missing Positive

43 Multiply Strings

49 Group Anagrams

53 Maximum Subarray

54 Spiral Matrix

62 Unique Paths

72 Edit Distance

99 Recover Binary Search Tree

103 Binary Tree Zigzag Level Order Traversal

116 Populating Next Right Pointers in Each Node

117 Populating Next Right Pointers in Each Node II

128 Longest Consecutive Sequence

138 Copy List with Random Pointer

139 Word Break

146 LRU Cache

151 Reverse Words in a String

200 Number of Islands

210 Course Schedule II

212 Word Search II

218 The Skyline Problem

224 Basic Calculator

227 Basic Calculator II

236 Lowest Common Ancestor of a Binary Tree

243 Shortest Word Distance

273 Integer to English Words

277 Find the Celebrity

295 Find Median from Data Stream

297 Serialize and Deserialize Binary Tree

348 Design Tic-Tac-Toe

相关题目: Valid Tic-Tac-Toe State

class TicTacToe {
   
    /*
    If at any time a row or column matches the size of the board then that player has won.
    */
    private int[] rows;
    private int[] cols;
    private int diagonal;  // 左上到右下的对角线1
    private int antiDiagonal; // 右上到左下的对角线2
    private int n;
    
    /** Initialize your data structure here. */
    public TicTacToe(int n) {
   
        rows = new int[n];
        cols = new int[n];
        this.n = n;
        diagonal = 0;
        antiDiagonal = 0;
    }
    
    /** Player {player} makes a move at ({row}, {col}).
        @param row The row of the board.
        @param col The column of the board.
        @param player The player, can be either 1 or 2.
        @return The current winning condition, can be either:
                0: No one wins.
                1: Player 1 wins.
                2: Player 2 wins. */
    public int move(int row, int col, int player) {
   
        int val = (player == 1) ? 1 : -1;
        int target = (player == 1) ? n : -n;
        
        
        //  判断 对角线1
        if(row == col){
   
            diagonal += val;
            if(diagonal == target){
   
                return player;
            }
        }
        
        // 判断 对角线2
        if(row == n-col-1){
   
            antiDiagonal += val;
            if(antiDiagonal == target){
   
                return player;
            }
        }
        
        rows[row] += val;
        cols[col] += val;
        
        if(rows[row] == target || cols[col] == target) return player;
        return 0;
        
    }
}

/**
 * Your TicTacToe object will be instantiated and called as such:
 * TicTacToe obj = new TicTacToe(n);
 * int param_1 = obj.move(row,col,player);
 */ 

428 Serialize and Deserialize N-ary Tree

443 String Compression

class Solution {
   
    public int compress(char[] chars) {
   
        int left = 0;
        int size = 0;
        int n = chars.length;
        for (int i = 0; i <= n; ++i) {
   
            // 当遍历完成,或右指针元素不等于左指针元素时,更新数组
            if (i == n || chars[i] != chars[left]) {
   
                // 更新字符
                chars[size++] = chars[left];
                // 更新计数,当个数大于 1 时才更新
                if (i - left > 1) {
   
                    for (char c : String.valueOf(i - left).toCharArray()) {
   
                        chars[size++] = c
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值