• LeetCode Weekly Contest 258


    第一题

    class Solution {
        public String reversePrefix(String word, char ch) {
            int index = word.indexOf(ch + "");
            if (index != -1) {
              String s = word.substring(0, index+1);
              StringBuilder stringBuilder = new StringBuilder(s);
              return stringBuilder.reverse().toString()+word.substring(index+1);
            }
            return word;
        }
    }
    

    第二题

    class Solution {
        public long interchangeableRectangles(int[][] r) {
             int n = r.length;
            double[] rate = new double[n];
            for (int i = 0; i < n; i++) {
              rate[i] = (double) r[i][0] / (double) r[i][1];
            }
            Arrays.sort(rate);
            long res = 0;
            for (int i = 0; i < n; i++) {
              int j = i + 1;
              while (j < n && rate[i] == rate[j]) {
                j++;
              }
              long len = j - i;
              res += (len * (len - 1)) / 2;
              i = j-1;
            }
            return res;
        }
    }
    

    第三题

    class Solution {
    public:
        int ans = 0, n;
        string S;
        bool check(string v){
            int m = v.size();
            for(int i=0; i<m; i++){
                if(v[i] != v[m-1-i]) return false;
            }
            return true;
        }
        void dfs(int u, string l, string r){
            if(u == n){
                int t = l.size() * r.size();
                if(t <= ans) return;
                if(check(l) && check(r)){
                    ans = max(ans, t);
                }
                return;
            }
            dfs(u+1, l, r);
            dfs(u+1,l+S[u], r);
            dfs(u+1, l, r+S[u]);
        }
        int maxProduct(string s) {
            n  = s.size();
            S = s;
            dfs(0, "", "");
            return ans;
        }
    };
    
  • 相关阅读:
    KafKa 发消息到Storm
    HBase的优化
    HBase部署与使用
    Scala 类
    Scala高阶函数
    模式匹配
    Scala数据结构
    scala基础语法
    Scala安装配置
    Kafka工作流程分析
  • 原文地址:https://www.cnblogs.com/lzeffort/p/15259117.html
Copyright © 2020-2023  润新知