290. Word Pattern

290. Word Pattern

class Solution {
    public boolean wordPattern(String pattern, String s) {
        HashMap<Character,String> map = new HashMap<>();
        String[] sWords = s.split(" ");
        if(sWords.length != pattern.length()) return false;
        for(int i = 0; i < pattern.length(); i++){
            for (Map.Entry<Character, String> entry : map.entrySet()) {
                if(entry.getValue().equals(sWords[i]) && entry.getKey() != pattern.charAt(i)) return false;
                 if(!entry.getValue().equals(sWords[i]) && entry.getKey() == pattern.charAt(i)) return false;
            }
                 map.put(pattern.charAt(i),sWords[i]);

        }
        return true;
    }
}

اليوم القرآنى – جامع الخليل

حلقات جامع الخليل إبراهيم (عليه السلام) بحى الفيحاء بأن المشارك

شهادة اجتياز

تشهد حلقات جامع الخليل إبراهيم – عليه السلام – بحى الفيحاء

بأن المشارك / عمر خميس مصطفى جمال الدين

قد اجتاز الفرع الأول – القرآن كاملا – وذلك فى اليوم القرآنى الثالث المقام بالجامع يوم السبت 26/3/1444 هـ الموافق 22/10/2022 م

سائلين المولى له التوفيق والسداد

Balanced Brackets

Balanced Brackets

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class Result {

    /*
     * Complete the 'isBalanced' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts STRING s as parameter.
     */

    public static String isBalanced(String s) {
    // Write your code here
Stack<Character> stack = new Stack<Character>();
for(int i = 0; i < s.length(); i++){
    if("{([".contains(s.charAt(i)+"")) stack.push(s.charAt(i));
    else if(s.charAt(i) == ']'){
        if(stack.isEmpty()) return "NO";
        if(stack.peek() != '[') return "NO";
        stack.pop();
                }
    else if(s.charAt(i) == '}'){
        if(stack.isEmpty()) return "NO";
        if(stack.peek() != '{') return "NO";
        stack.pop();
                }
    else if(s.charAt(i) == ')'){
        if(stack.isEmpty()) return "NO";
        if(stack.peek() != '(') return "NO";
        stack.pop();
                }
}
if(!stack.isEmpty()) return "NO";
return "YES";

    }

}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int t = Integer.parseInt(bufferedReader.readLine().trim());

        IntStream.range(0, t).forEach(tItr -> {
            try {
                String s = bufferedReader.readLine();

                String result = Result.isBalanced(s);

                bufferedWriter.write(result);
                bufferedWriter.newLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });

        bufferedReader.close();
        bufferedWriter.close();
    }
}

Merge two sorted linked lists

Merge two sorted linked lists

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {

    static class SinglyLinkedListNode {
        public int data;
        public SinglyLinkedListNode next;

        public SinglyLinkedListNode(int nodeData) {
            this.data = nodeData;
            this.next = null;
        }
    }

    static class SinglyLinkedList {
        public SinglyLinkedListNode head;
        public SinglyLinkedListNode tail;

        public SinglyLinkedList() {
            this.head = null;
            this.tail = null;
        }

        public void insertNode(int nodeData) {
            SinglyLinkedListNode node = new SinglyLinkedListNode(nodeData);

            if (this.head == null) {
                this.head = node;
            } else {
                this.tail.next = node;
            }

            this.tail = node;
        }
    }

    public static void printSinglyLinkedList(SinglyLinkedListNode node, String sep, BufferedWriter bufferedWriter) throws IOException {
        while (node != null) {
            bufferedWriter.write(String.valueOf(node.data));

            node = node.next;

            if (node != null) {
                bufferedWriter.write(sep);
            }
        }
    }

    // Complete the mergeLists function below.

    /*
     * For your reference:
     *
     * SinglyLinkedListNode {
     *     int data;
     *     SinglyLinkedListNode next;
     * }
     *
     */
    static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {
        SinglyLinkedListNode out;
        if(head1.data <= head2.data){
        out = new SinglyLinkedListNode(head1.data);
        head1 = head1.next;
        }else{
            out = new SinglyLinkedListNode(head2.data);
            head2 = head2.next;
        }
        SinglyLinkedListNode last = out;
        while(head1 != null || head2 != null){
            
            if(head1 == null){
                last.next = head2;
                last = last.next;
                head2 = head2.next;
            }else if( head2 == null){
                last.next = head1;
                last = last.next;
                head1 = head1.next;
            }
            else if(head1.data <= head2.data){
                last.next = head1;
                last = last.next;
                head1 = head1.next;
            }else if(head1.data > head2.data){
                last.next = head2;
                last = last.next;
                head2 = head2.next;
            }
        }

return out;
    }

    private static final Scanner scanner = new Scanner(System.in);

يوم الهمة – جامع الصفيان

جمعية تحفيظ القرآن بالرياض – مكنون
تشهد حلقات جامع الشيخ ناصر بن سعد الصفيان -رحمه الله- بأن المشارك
عمر خميس جمال الدين
قد قام بعرض القرآن الكريم كاملا أثناء مشاركته فى فرع (ثلاثون جزءا) من سورة الفاتحة إلى سورة الناس
وذلك فى يوم الهمة المقام بالجامع بتاريخ 18/11/1443 هـ
سائلين المولى عز وجل له التوفيق والسداد

شهادة حضور اليوم القرآنى بجامع الراجحى بالرياض

جمعية تحفيظ القرآن بالرياض – مكنون
شهادة حضور
تشهد إدارة الشئون التعليمية بجميعة تحفيظ القرآن الكريم بالرياض (مكنون) بأن الطالب/ عمر خميس جمال الدين شارك فى اليوم القرآنى المقام فى جامع الراجحى يوم السبت الموافق 3/12/1443 هـ سائلين الله له مزيدا من التوفيق والنجاح
مدير إدارة الشئون التعليمية